pub struct Model<W, T = DynHttpClient> {
pub wire: W,
pub transport: T,
}Expand description
An endpoint of one provider: a wire bound to a transport.
The pair holds no invariant, so both halves are public. To share one
transport across models, clone it; to send a model’s requests another
way, replace its transport. The transport defaults to the erased HTTP
client, so a model on the default transport is Model<W>.
Fields§
§wire: WWhat to send and how to read the reply.
transport: THow the payload travels.
Implementations§
Source§impl<T> Model<CachedContents, T>where
T: Transport<CachedContents>,
Explicit context-cache operations. Requests targeting an existing handle
map HTTP 403 and 404 to ProviderError::CacheExpired.
impl<T> Model<CachedContents, T>where
T: Transport<CachedContents>,
Explicit context-cache operations. Requests targeting an existing handle
map HTTP 403 and 404 to ProviderError::CacheExpired.
Sourcepub async fn create(
&self,
request: NewCachedContent,
) -> Result<CachedContent, ProviderError>
pub async fn create( &self, request: NewCachedContent, ) -> Result<CachedContent, ProviderError>
Creates cached content and returns its handle and storage usage metadata.
Sourcepub async fn get(&self, name: &str) -> Result<CachedContent, ProviderError>
pub async fn get(&self, name: &str) -> Result<CachedContent, ProviderError>
Fetch one cached content by handle.
Sourcepub async fn list(&self) -> Result<Vec<CachedContent>, ProviderError>
pub async fn list(&self) -> Result<Vec<CachedContent>, ProviderError>
Every cached content this API key can see, following pagination at the wire’s page size.
Sourcepub async fn update_expiry(
&self,
name: &str,
expiry: CacheExpiry,
) -> Result<CachedContent, ProviderError>
pub async fn update_expiry( &self, name: &str, expiry: CacheExpiry, ) -> Result<CachedContent, ProviderError>
Changes cache expiry without modifying its immutable content.
Returns the updated resource or an error, including Expired for HTTP 403/404.
Sourcepub async fn delete(&self, name: &str) -> Result<(), ProviderError>
pub async fn delete(&self, name: &str) -> Result<(), ProviderError>
Deletes cached content before its expiry. Callers should also clean up
task-scoped caches on failure to avoid continued storage charges.
Handles other than cachedContents/<id> or bare <id> return
ProviderError::Request before dispatch.
Source§impl<T> Model<GenerateContent, T>
impl<T> Model<GenerateContent, T>
Sourcepub fn caching(self, book: &CacheBook) -> Model<GenerateContent, Caching<T>>
pub fn caching(self, book: &CacheBook) -> Model<GenerateContent, Caching<T>>
This model, reading and creating explicit caches as book decides.
See crate::providers::gemini::caching.
Source§impl<W, T> Model<W, T>
impl<W, T> Model<W, T>
Sourcepub fn id(&self) -> Option<&str>
pub fn id(&self) -> Option<&str>
The model id the wire addresses, when the operation addresses one.
Sourcepub fn capabilities(&self) -> Capabilities
pub fn capabilities(&self) -> Capabilities
What a runtime accounts for about this model, such as an embedding model’s width.
Sourcepub fn call(
&self,
request: impl Into<Request<W>>,
) -> impl Future<Output = Result<Response<W>, ProviderError>> + WasmCompatSend + 'static
pub fn call( &self, request: impl Into<Request<W>>, ) -> impl Future<Output = Result<Response<W>, ProviderError>> + WasmCompatSend + 'static
Send request and fold the whole reply into the operation’s
response: Self::stream of a unary reply, finished. A completion
takes a prompt, a conversation or a
CompletionRequest.
Sourcepub fn call_observed(
&self,
request: impl Into<Request<W>>,
observation: AdapterContext,
) -> impl Future<Output = Result<Response<W>, ProviderError>> + WasmCompatSend + 'static
pub fn call_observed( &self, request: impl Into<Request<W>>, observation: AdapterContext, ) -> impl Future<Output = Result<Response<W>, ProviderError>> + WasmCompatSend + 'static
Self::call, with the attempt observed under observation.
Sourcepub fn stream(
&self,
request: impl Into<Request<W>>,
) -> Result<Streamed<W::Op>, ProviderError>
pub fn stream( &self, request: impl Into<Request<W>>, ) -> Result<Streamed<W::Op>, ProviderError>
Open a streamed reply. Encoding errors return here; every later failure arrives in-band, as the stream’s last item. Nothing is sent until the stream is first polled.
Sourcepub fn stream_observed(
&self,
request: impl Into<Request<W>>,
observation: AdapterContext,
) -> Result<Streamed<W::Op>, ProviderError>
pub fn stream_observed( &self, request: impl Into<Request<W>>, observation: AdapterContext, ) -> Result<Streamed<W::Op>, ProviderError>
Self::stream, with the attempt observed under observation.
Source§impl<W, T> Model<W, T>
impl<W, T> Model<W, T>
Sourcepub async fn embed_text(&self, text: &str) -> Result<Embedding, ProviderError>
pub async fn embed_text(&self, text: &str) -> Result<Embedding, ProviderError>
Embed one text, returning the last vector or an error if none is returned.
Source§impl<W, T> Model<W, T>
impl<W, T> Model<W, T>
Sourcepub async fn list(&self) -> Result<ModelList, ProviderError>
pub async fn list(&self) -> Result<ModelList, ProviderError>
Every model the provider lists, every page followed in order.
A failed page names the provider and its request path. Paging stops at a cursor that repeats the one just answered, and after a bounded number of pages.
Source§impl<W, T> Model<W, T>
impl<W, T> Model<W, T>
Sourcepub async fn verify(&self) -> Result<(), ProviderError>
pub async fn verify(&self) -> Result<(), ProviderError>
Check that the provider accepts the configured credentials. A 401 or
403 reply is ProviderError::InvalidAuthentication.
Source§impl<T> Model<GenerateContent, T>
impl<T> Model<GenerateContent, T>
Sourcepub fn thought_replay(self, replay: ThoughtReplay) -> Self
pub fn thought_replay(self, replay: ThoughtReplay) -> Self
This model, re-sending thought signatures as replay says. See
ThoughtReplay. Call it before caching, which
reads it.
Source§impl<T> Model<Responses, T>
impl<T> Model<Responses, T>
Sourcepub fn responses_websocket(&self) -> ResponsesWebSocketSessionBuilder
Available on crate feature websocket only.
pub fn responses_websocket(&self) -> ResponsesWebSocketSessionBuilder
websocket only.Start configuring a Responses WebSocket session for this model. Open
it with connect_with
and a backend, or, under the tungstenite feature, with
connect.
Source§impl Model<MockScript, MockRuntime>
impl Model<MockScript, MockRuntime>
Sourcepub fn text(text: impl Into<String>) -> Self
Available on crate feature test-utils only.
pub fn text(text: impl Into<String>) -> Self
test-utils only.Create a mock model that returns one text completion.
Sourcepub fn from_turns(turns: impl IntoIterator<Item = MockTurn>) -> Self
Available on crate feature test-utils only.
pub fn from_turns(turns: impl IntoIterator<Item = MockTurn>) -> Self
test-utils only.Create a mock model from scripted non-streaming turns.
Sourcepub fn from_stream_turns(
stream_turns: impl IntoIterator<Item = impl IntoIterator<Item = MockStreamEvent>>,
) -> Self
Available on crate feature test-utils only.
pub fn from_stream_turns( stream_turns: impl IntoIterator<Item = impl IntoIterator<Item = MockStreamEvent>>, ) -> Self
test-utils only.Create a mock model from scripted streaming turns.
Sourcepub fn requests(&self) -> Vec<CompletionRequest>
Available on crate feature test-utils only.
pub fn requests(&self) -> Vec<CompletionRequest>
test-utils only.Return cloned requests received by this model.
Sourcepub fn contexts(&self) -> Vec<Option<AdapterContext>>
Available on crate feature test-utils only.
pub fn contexts(&self) -> Vec<Option<AdapterContext>>
test-utils only.Return invocation contexts in the same order as the captured requests.
Sourcepub fn request_count(&self) -> usize
Available on crate feature test-utils only.
pub fn request_count(&self) -> usize
test-utils only.Return the number of requests received by this model.
Sourcepub fn script(&self) -> Vec<MockTurn>
Available on crate feature test-utils only.
pub fn script(&self) -> Vec<MockTurn>
test-utils only.The non-streaming turns not yet consumed, in order — the read-back half of the script, so a script is serde in and serde out.
Sourcepub fn stream_script(&self) -> Vec<Vec<MockStreamEvent>>
Available on crate feature test-utils only.
pub fn stream_script(&self) -> Vec<Vec<MockStreamEvent>>
test-utils only.The streaming turns not yet consumed, in order.
Trait Implementations§
impl<W: PartialEq, T: PartialEq> StructuralPartialEq for Model<W, T>
Auto Trait Implementations§
impl<W, T> Freeze for Model<W, T>
impl<W, T> RefUnwindSafe for Model<W, T>where
W: RefUnwindSafe,
T: RefUnwindSafe,
impl<W, T> Send for Model<W, T>
impl<W, T> Sync for Model<W, T>
impl<W, T> Unpin for Model<W, T>
impl<W, T> UnsafeUnpin for Model<W, T>where
W: UnsafeUnpin,
T: UnsafeUnpin,
impl<W, T> UnwindSafe for Model<W, T>where
W: UnwindSafe,
T: UnwindSafe,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more