fix: make llm provider async and add tool toggle
This commit is contained in:
@@ -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, ¤t_history, &tools)
|
||||
.chat(&config.model, ¤t_history, tools)
|
||||
.await
|
||||
.map_err(|e| format!("LLM Error: {}", e))?;
|
||||
|
||||
// Process Response
|
||||
|
||||
Reference in New Issue
Block a user