Skip to main content

LocalChat

Struct LocalChat 

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

A local model behind the Model interface, so the same agent runs on device. Renders requests through the model’s chat template, generates on a blocking thread and cancels when the future is dropped.

Implementations§

Source§

impl LocalChat

Source

pub fn new(model: Arc<dyn LocalModel>, id: impl Into<String>) -> Self

Wraps a loaded local model with default settings. Input: the model and the id Model::id returns. Output: the chat model.

Source

pub fn with_settings(self, settings: LocalChatSettings) -> Self

Replaces the settings. Input: the settings. Output: the chat model.

Source

pub fn settings(&self) -> &LocalChatSettings

Returns the settings. Input: none. Output: the settings.

Trait Implementations§

Source§

impl Debug for LocalChat

Source§

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

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

impl Model for LocalChat

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 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.
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 'life0: 'async_trait, 'life1: 'async_trait, Self: '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 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait, Self: '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.

Auto Trait Implementations§

§

impl !RefUnwindSafe for LocalChat

§

impl !UnwindSafe for LocalChat

§

impl Forget for LocalChat

§

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

§

impl Move for LocalChat

§

impl Send for LocalChat
where Arc<dyn LocalModel>: Send, RawVecInner: Send,

§

impl Sync for LocalChat
where Arc<dyn LocalModel>: Sync, RawVecInner: Sync,

§

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

§

impl UnsafeUnpin for LocalChat
where *const ArcInner<dyn LocalModel> is !null: UnsafeUnpin, PhantomData<ArcInner<dyn LocalModel>>: UnsafeUnpin, *const u8 is !null: UnsafeUnpin, PhantomData<u8>: 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<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> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

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.