Skip to main content

HttpModel

Struct HttpModel 

Source
pub struct HttpModel { /* private fields */ }
Expand description

A model reached over HTTP through an injected Transport. Unary and streamed calls share one encoder, one decoder per protocol and one Fold, so both return the same response for the same reply.

Implementations§

Source§

impl HttpModel

Source

pub fn new( id: impl Into<String>, model: impl Into<String>, endpoint: Endpoint, key: Option<Secret>, transport: Arc<dyn Transport>, ) -> Result<Self, ProviderError>

Builds a model named id (usually vendor/model) that sends wire model to endpoint with an optional key through transport. Returns BadRequest when model fails valid_model_id.

Trait Implementations§

Source§

impl Model for HttpModel

Source§

fn id(&self) -> &str

Source§

fn complete<'life0, 'life1, 'async_trait>( &'life0 self, req: &'life1 CompletionRequest, ) -> Pin<Box<dyn Future<Output = Result<CompletionResponse, ProviderError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Source§

fn stream<'life0, 'life1, 'life2, 'async_trait>( &'life0 self, req: &'life1 CompletionRequest, on_delta: &'life2 mut (dyn for<'d> FnMut(&'d Delta) + Send), ) -> Pin<Box<dyn Future<Output = Result<CompletionResponse, ProviderError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait,

Source§

fn complete_billed<'life0, 'life1, 'async_trait>( &'life0 self, req: &'life1 CompletionRequest, ) -> Pin<Box<dyn Future<Output = Result<CompletionResponse, FailedCall>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Runs complete and, when the call fails, keeps the usage the provider reported before it failed, so a caller can bill it. Default: complete with zero usage. A model that sees usage overrides it, and a wrapper forwards it to its inner model.
Source§

fn stream_billed<'life0, 'life1, 'life2, 'async_trait>( &'life0 self, req: &'life1 CompletionRequest, on_delta: &'life2 mut (dyn for<'d> FnMut(&'d Delta) + Send), ) -> Pin<Box<dyn Future<Output = Result<CompletionResponse, FailedCall>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait,

Runs stream and, when the call fails, keeps the usage the provider reported before it failed, as complete_billed does. Default: stream with zero usage.
Source§

fn prices_replies(&self) -> bool

Reports whether each reply’s usage.cost_usd_micros is already the cost of the model that served it, as a routed or metered model’s is. A run then bills that cost instead of its own price, so a retry or fallback that sums priced tries is billed that sum. Default false.
Source§

fn meter_price(&self) -> Option<Price>

Returns the price that meters each try when every reply is priced at one price, as a metered model and a retry over one are. A caller trusts the reply cost only when it equals its own declared price. Default None.
Source§

fn extra_calls(&self, req: &CompletionRequest) -> u32

Returns how many more provider calls one call with req can make after the first, each resending req with the previous reply and at most RESEND_NOTE_BYTES of note. A run budgets them before the call. Default 0.

Auto Trait Implementations§

§

impl !RefUnwindSafe for HttpModel

§

impl !UnwindSafe for HttpModel

§

impl Forget for HttpModel

§

impl Freeze for HttpModel
where *const u8 is !null: Freeze, PhantomData<u8>: Freeze, *const ArcInner<dyn Transport> is !null: Freeze, PhantomData<ArcInner<dyn Transport>>: Freeze,

§

impl Move for HttpModel

§

impl Send for HttpModel
where RawVecInner: Send, Arc<dyn Transport>: Send,

§

impl Sync for HttpModel
where RawVecInner: Sync, Arc<dyn Transport>: Sync,

§

impl Unpin for HttpModel
where *const u8 is !null: Unpin, Arc<dyn Transport>: Unpin,

§

impl UnsafeUnpin for HttpModel
where *const u8 is !null: UnsafeUnpin, PhantomData<u8>: UnsafeUnpin, *const ArcInner<dyn Transport> is !null: UnsafeUnpin, PhantomData<ArcInner<dyn Transport>>: UnsafeUnpin,

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<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> 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, 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<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