pub struct ChatEngine { /* private fields */ }Expand description
High-level chat engine that maintains conversation state.
Wraps an Engine with conversation history, context management,
and automatic chat template formatting.
Implementations§
Source§impl ChatEngine
impl ChatEngine
Sourcepub fn new(engine: Engine, system_prompt: Option<String>) -> Self
pub fn new(engine: Engine, system_prompt: Option<String>) -> Self
Create a new chat engine from a loaded Engine.
Sourcepub fn system_prompt(&self) -> &str
pub fn system_prompt(&self) -> &str
Get the current system prompt.
Sourcepub fn context_len(&self) -> usize
pub fn context_len(&self) -> usize
Get the number of tokens in the current conversation context.
Sourcepub fn chat(&mut self, message: &str) -> Result<String, EngineError>
pub fn chat(&mut self, message: &str) -> Result<String, EngineError>
Send a message and get the full response.
Sourcepub fn chat_with_prefix(
&mut self,
message: &str,
prefix: &str,
) -> Result<String, EngineError>
pub fn chat_with_prefix( &mut self, message: &str, prefix: &str, ) -> Result<String, EngineError>
Send a message and get the full response, with a prefix injected as the start of the assistant’s reply. The prefix tokens are prefilled alongside the prompt tokens so the model continues from the prefix text. The prefix is prepended to the returned string.
This is useful for forcing the model to start with a particular token
sequence (e.g. { for JSON output).
Sourcepub fn chat_streaming(
&mut self,
message: &str,
) -> Result<ChatStream<'_>, EngineError>
pub fn chat_streaming( &mut self, message: &str, ) -> Result<ChatStream<'_>, EngineError>
Send a message and stream the response token by token.
Returns an iterator of Result<String, EngineError> where each item is
a decoded token chunk.
Sourcepub fn clear_history(&mut self)
pub fn clear_history(&mut self)
Clear conversation history and reset context.
Auto Trait Implementations§
impl !RefUnwindSafe for ChatEngine
impl !UnwindSafe for ChatEngine
impl Freeze for ChatEngine
impl Send for ChatEngine
impl Sync for ChatEngine
impl Unpin for ChatEngine
impl UnsafeUnpin for ChatEngine
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<A, B, T> HttpServerConnExec<A, B> for Twhere
B: Body,
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