pub struct Conversation { /* private fields */ }Expand description
Stateful conversation that accumulates chat history across turns
Implementations§
Source§impl Conversation
impl Conversation
Sourcepub fn new(client: HttpClient) -> Self
pub fn new(client: HttpClient) -> Self
Create a new conversation using the given HTTP client
§Example
use wauldo::{HttpClient, Conversation};
let client = HttpClient::localhost().unwrap();
let conv = Conversation::new(client);Sourcepub fn with_system(self, system: &str) -> Self
pub fn with_system(self, system: &str) -> Self
Add a system message to the conversation history
The system message is always inserted at position 0 so it precedes all user and assistant turns.
§Example
let conv = Conversation::new(client)
.with_system("You are a helpful Rust expert");Sourcepub fn with_model(self, model: &str) -> Self
pub fn with_model(self, model: &str) -> Self
Set the model to use for chat completions
Defaults to "default" (server-selected) if not called.
§Example
let conv = Conversation::new(client).with_model("llama3");Sourcepub async fn say(&mut self, message: &str) -> Result<String>
pub async fn say(&mut self, message: &str) -> Result<String>
Send a user message, receive the assistant reply, and store both in history
The full accumulated history (system + prior turns) is sent with each request so the LLM has complete conversational context.
§Example
let mut conv = Conversation::new(client).with_system("Be concise");
let reply = conv.say("What is Rust?").await?;
println!("{}", reply);Sourcepub fn history(&self) -> &[ChatMessage]
pub fn history(&self) -> &[ChatMessage]
Read-only access to the accumulated history
§Example
let conv = Conversation::new(client).with_system("sys");
assert_eq!(conv.history().len(), 1);Sourcepub fn clear(&mut self)
pub fn clear(&mut self)
Clear conversation history (keeps model setting and system prompt)
Removes all user and assistant messages but preserves the system prompt
(if any) so subsequent say() calls retain the same persona.
§Example
let mut conv = Conversation::new(client).with_system("sys");
conv.clear();
assert_eq!(conv.history().len(), 1); // system prompt preserved