Skip to main content

Model

Struct Model 

Source
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: W

What to send and how to read the reply.

§transport: T

How the payload travels.

Implementations§

Source§

impl<T> Model<CachedContents, T>

Explicit context-cache operations. Requests targeting an existing handle map HTTP 403 and 404 to ProviderError::CacheExpired.

Source

pub async fn create( &self, request: NewCachedContent, ) -> Result<CachedContent, ProviderError>

Creates cached content and returns its handle and storage usage metadata.

Source

pub async fn get(&self, name: &str) -> Result<CachedContent, ProviderError>

Fetch one cached content by handle.

Source

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.

Source

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.

Source

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>

Source

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>
where W: Wire, T: Transport<W>,

Source

pub fn erase(self) -> DynModel<W::Op>

Erase this model to its operation.

Source§

impl<W, T> Model<W, T>

Source

pub fn new(wire: W, transport: T) -> Self

Pair wire with the transport that sends it.

Source§

impl<W, T> Model<W, T>
where W: Wire, T: Transport<W>,

Source

pub fn name(&self) -> &str

The wire’s provider descriptor name ("anthropic").

Source

pub fn id(&self) -> Option<&str>

The model id the wire addresses, when the operation addresses one.

Source

pub fn capabilities(&self) -> Capabilities

What a runtime accounts for about this model, such as an embedding model’s width.

Source

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.

Source

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.

Source

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.

Source

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>
where W: Wire<Op = Embedding>, T: Transport<W>,

Source

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>
where W: Wire<Op = ModelListing>, T: Transport<W>,

Source

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>
where W: Wire<Op = Verify>, T: Transport<W>,

Source

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>

Source

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>

Source

pub fn responses_websocket(&self) -> ResponsesWebSocketSessionBuilder

Available on crate feature 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>

Source

pub fn text(text: impl Into<String>) -> Self

Available on crate feature test-utils only.

Create a mock model that returns one text completion.

Source

pub fn from_turns(turns: impl IntoIterator<Item = MockTurn>) -> Self

Available on crate feature test-utils only.

Create a mock model from scripted non-streaming turns.

Source

pub fn from_stream_turns( stream_turns: impl IntoIterator<Item = impl IntoIterator<Item = MockStreamEvent>>, ) -> Self

Available on crate feature test-utils only.

Create a mock model from scripted streaming turns.

Source

pub fn requests(&self) -> Vec<CompletionRequest>

Available on crate feature test-utils only.

Return cloned requests received by this model.

Source

pub fn contexts(&self) -> Vec<Option<AdapterContext>>

Available on crate feature test-utils only.

Return invocation contexts in the same order as the captured requests.

Source

pub fn request_count(&self) -> usize

Available on crate feature test-utils only.

Return the number of requests received by this model.

Source

pub fn script(&self) -> Vec<MockTurn>

Available on crate feature 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.

Source

pub fn stream_script(&self) -> Vec<Vec<MockStreamEvent>>

Available on crate feature test-utils only.

The streaming turns not yet consumed, in order.

Trait Implementations§

Source§

impl<W: Clone, T: Clone> Clone for Model<W, T>

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<W: Debug, T: Debug> Debug for Model<W, T>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<W: Default, T: Default> Default for Model<W, T>

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl<W, T> From<Model<W, T>> for DynModel<W::Op>
where W: Wire, T: Transport<W>,

Source§

fn from(model: Model<W, T>) -> Self

Converts to this type from the input type.
Source§

impl<W: PartialEq, T: PartialEq> PartialEq for Model<W, T>

Source§

fn eq(&self, other: &Self) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl<W: PartialEq, T: PartialEq> StructuralPartialEq for Model<W, T>

Auto Trait Implementations§

§

impl<W, T> Freeze for Model<W, T>
where W: Freeze, T: Freeze,

§

impl<W, T> RefUnwindSafe for Model<W, T>

§

impl<W, T> Send for Model<W, T>
where W: Send, T: Send,

§

impl<W, T> Sync for Model<W, T>
where W: Sync, T: Sync,

§

impl<W, T> Unpin for Model<W, T>
where W: Unpin, T: Unpin,

§

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> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> DynClone for T
where T: Clone,

Source§

fn __clone_box(&self, _: Private) -> *mut ()

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
where F: FnOnce(&Self) -> bool,

Converts 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
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WasmCompatSend for T
where T: Send,

Source§

impl<T> WasmCompatSync for T
where T: Sync,

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more