Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove lifecycle specifiers for Coordinator #104

Merged
merged 15 commits into from
Dec 30, 2024
Merged
8 changes: 3 additions & 5 deletions examples/coordinator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ use ollama_rs::{coordinator::Coordinator, generation::chat::ChatMessage, Ollama}

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let mut ollama = Ollama::default();
let mut history = vec![];
let mut coordinator = Coordinator::new(&mut ollama, "llama3.2".to_string(), &mut history);
let ollama = Ollama::default();
let history = vec![];
let mut coordinator = Coordinator::new(ollama, "llama3.2".to_string(), history);

let stdin = stdin();
let mut stdout = stdout();
Expand All @@ -29,7 +29,5 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
println!("{}", resp.message.content);
}

dbg!(history);

Ok(())
}
8 changes: 3 additions & 5 deletions examples/coordinator_tool_call.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {

let debug = args.get(1).is_some();

let mut ollama = Ollama::default();
let mut history = vec![];
let ollama = Ollama::default();
let history = vec![];
let tools = (DDGSearcher::new(), (Scraper {}, Calculator {}));

let mut coordinator =
Coordinator::new_with_tools(&mut ollama, "qwen2.5:32b".to_string(), &mut history, tools)
Coordinator::new_with_tools(ollama, "qwen2.5:32b".to_string(), history, tools)
.options(GenerationOptions::default().num_ctx(16384))
.debug(debug);

Expand All @@ -50,7 +50,5 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
println!("{}", resp.message.content);
}

dbg!(history);

Ok(())
}
21 changes: 8 additions & 13 deletions src/coordinator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,17 @@ use crate::{
Ollama,
};

pub struct Coordinator<'a, 'b, C: ChatHistory, T: ToolGroup> {
pub struct Coordinator<C: ChatHistory, T: ToolGroup> {
model: String,
ollama: &'a mut Ollama,
ollama: Ollama,
options: GenerationOptions,
history: &'b mut C,
history: C,
tools: T,
debug: bool,
}

impl<'a, 'b, C: ChatHistory> Coordinator<'a, 'b, C, ()> {
pub fn new(ollama: &'a mut Ollama, model: String, history: &'b mut C) -> Self {
impl<C: ChatHistory> Coordinator<C, ()> {
pub fn new(ollama: Ollama, model: String, history: C) -> Self {
Self {
model,
ollama,
Expand All @@ -30,13 +30,8 @@ impl<'a, 'b, C: ChatHistory> Coordinator<'a, 'b, C, ()> {
}
}

impl<'a, 'b, C: ChatHistory, T: ToolGroup> Coordinator<'a, 'b, C, T> {
pub fn new_with_tools(
ollama: &'a mut Ollama,
model: String,
history: &'b mut C,
tools: T,
) -> Self {
impl<C: ChatHistory, T: ToolGroup> Coordinator<C, T> {
pub fn new_with_tools(ollama: Ollama, model: String, history: C, tools: T) -> Self {
Self {
model,
ollama,
Expand Down Expand Up @@ -71,7 +66,7 @@ impl<'a, 'b, C: ChatHistory, T: ToolGroup> Coordinator<'a, 'b, C, T> {
let resp = self
.ollama
.send_chat_messages_with_history(
self.history,
&mut self.history,
ChatMessageRequest::new(self.model.clone(), messages)
.options(self.options.clone())
.tools::<T>(),
Expand Down
Loading