From cb5ed9baf8285ce390eee466bf32bef7c696b575 Mon Sep 17 00:00:00 2001 From: zipg Date: Fri, 10 Jul 2026 23:05:08 +0800 Subject: [PATCH] fix(ai): disable Ollama thinking with reasoning effort --- crates/dbx-core/src/ai.rs | 115 +++++++++++++++++++++++++++++--------- 1 file changed, 90 insertions(+), 25 deletions(-) diff --git a/crates/dbx-core/src/ai.rs b/crates/dbx-core/src/ai.rs index 03ea1e6df..dcfaa8a0d 100644 --- a/crates/dbx-core/src/ai.rs +++ b/crates/dbx-core/src/ai.rs @@ -525,6 +525,22 @@ fn is_kimi_model(model: &str) -> bool { } } +fn apply_chat_completion_thinking_toggle(body: &mut serde_json::Value, config: &AiConfig) { + if config.enable_thinking { + return; + } + + if matches!(config.provider, AiProvider::Ollama) { + // Ollama's OpenAI-compatible API uses reasoning_effort instead of + // forwarding provider-specific chat template arguments. + body["reasoning_effort"] = json!("none"); + } else if !is_kimi_model(&config.model) { + body["extra_body"] = json!({ + "chat_template_kwargs": { "enable_thinking": false } + }); + } +} + fn responses_text(data: &serde_json::Value) -> String { if let Some(text) = data["output_text"].as_str().filter(|text| !text.is_empty()) { return text.to_string(); @@ -904,11 +920,7 @@ pub async fn call_openai_compatible(client: &reqwest::Client, request: AiComplet "messages": messages, }); set_chat_completion_token_limit(&mut body_obj, &request.config, request.max_tokens.unwrap_or(2048)); - if !request.config.enable_thinking && !is_kimi_model(&request.config.model) { - body_obj["extra_body"] = json!({ - "chat_template_kwargs": { "enable_thinking": false } - }); - } + apply_chat_completion_thinking_toggle(&mut body_obj, &request.config); let res = client .post(resolve_endpoint(&request.config)) @@ -1162,10 +1174,8 @@ pub async fn test_connection_core(config: &AiConfig) -> Result