Skip to main content

StreamingChat

Trait StreamingChat 

Source
pub trait StreamingChat<M, R>: WasmCompatSend + WasmCompatSync{
    type Hook: PromptHook<M>;

    // Required method
    fn stream_chat(
        &self,
        prompt: impl Into<Message> + WasmCompatSend,
        chat_history: Vec<Message>,
    ) -> StreamingPromptRequest<M, Self::Hook>;
}
Expand description

Trait for high-level streaming chat interface with conversation history.

This trait provides an interface for streaming chat completions with support for maintaining conversation history. Implementations can optionally support prompt hooks for observing and controlling the agent’s execution lifecycle.

Required Associated Types§

Source

type Hook: PromptHook<M>

The hook type used by this streaming chat implementation.

If your implementation does not need prompt hooks, use () as the hook type:

impl<M, R> StreamingChat<M, R> for MyType<M>
where
    M: CompletionModel + 'static,
    // ... other bounds ...
{
    type Hook = ();

    fn stream_chat(
        &self,
        prompt: impl Into<Message>,
        chat_history: Vec<Message>,
    ) -> StreamingPromptRequest<M, ()> {
        // ...
    }
}

Required Methods§

Source

fn stream_chat( &self, prompt: impl Into<Message> + WasmCompatSend, chat_history: Vec<Message>, ) -> StreamingPromptRequest<M, Self::Hook>

Stream a chat with history to the model

The updated history (including the new prompt and response) is returned in FinalResponse::history().

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§

Source§

impl<M, P> StreamingChat<M, <M as CompletionModel>::StreamingResponse> for Agent<M, P>
where M: CompletionModel + 'static, M::StreamingResponse: GetTokenUsage, P: PromptHook<M> + 'static,

Source§

type Hook = P