fix: make llm provider async and add tool toggle

This commit is contained in:
Dave
2025-12-24 17:32:46 +00:00
parent d9cd16601b
commit b241c47fd9
8 changed files with 149 additions and 28 deletions

View File

@@ -4,7 +4,7 @@ use crate::llm::types::{
Message, ModelProvider, Role, ToolCall, ToolDefinition, ToolFunctionDefinition,
};
use crate::state::SessionState;
use serde::{Deserialize, Serialize};
use serde::Deserialize;
use serde_json::json;
use tauri::State;
@@ -13,6 +13,7 @@ pub struct ProviderConfig {
pub provider: String, // "ollama"
pub model: String,
pub base_url: Option<String>,
pub enable_tools: Option<bool>,
}
const MAX_TURNS: usize = 10;
@@ -34,7 +35,12 @@ pub async fn chat(
};
// 2. Define Tools
let tools = get_tool_definitions();
let tool_defs = get_tool_definitions();
let tools = if config.enable_tools.unwrap_or(true) {
tool_defs.as_slice()
} else {
&[]
};
// 3. Agent Loop
let mut current_history = messages.clone();
@@ -49,7 +55,8 @@ pub async fn chat(
// Call LLM
let response = provider
.chat(&config.model, &current_history, &tools)
.chat(&config.model, &current_history, tools)
.await
.map_err(|e| format!("LLM Error: {}", e))?;
// Process Response