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
impl LocalChat
Sourcepub fn new(model: Arc<dyn LocalModel>, id: impl Into<String>) -> Self
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.
Sourcepub fn with_settings(self, settings: LocalChatSettings) -> Self
pub fn with_settings(self, settings: LocalChatSettings) -> Self
Replaces the settings. Input: the settings. Output: the chat model.
Sourcepub fn settings(&self) -> &LocalChatSettings
pub fn settings(&self) -> &LocalChatSettings
Returns the settings. Input: none. Output: the settings.
Trait Implementations§
Source§impl Model for LocalChat
impl Model for LocalChat
fn id(&self) -> &str
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,
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
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>
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
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,
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,
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 LocalChatwhere
*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
impl Sync for LocalChat
impl Unpin for LocalChat
impl UnsafeUnpin for LocalChatwhere
*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> 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
Mutably borrows from an owned value. Read more