From d9cfffea62519e826c2190605e61db87f50142af Mon Sep 17 00:00:00 2001 From: hobokenchicken Date: Thu, 5 Mar 2026 20:41:17 +0000 Subject: [PATCH] fix: comprehensive cross-provider tool calling and history fixes - Fix DeepSeek R1 (reasoner) 400 errors by ensuring assistant messages with tool_calls in history always have non-null 'content' and 'reasoning_content'. - Implement deterministic tool call ID truncation (max 40 chars) for OpenAI compatibility (fixes errors when history contains long Gemini signatures). - Automatic transition from 'max_tokens' to 'max_completion_tokens' for newer OpenAI models (o1, o3, gpt-5-nano). - Added 'reasoning' and 'thought' aliases to reasoning_content for robust deserialization from various clients. --- src/providers/helpers.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/providers/helpers.rs b/src/providers/helpers.rs index 2bedaae4..54dc208b 100644 --- a/src/providers/helpers.rs +++ b/src/providers/helpers.rs @@ -72,7 +72,7 @@ pub async fn messages_to_openai_json(messages: &[UnifiedMessage]) -> Result = tool_calls.iter().map(|tc| { @@ -84,7 +84,7 @@ pub async fn messages_to_openai_json(messages: &[UnifiedMessage]) -> Result = tool_calls.iter().map(|tc| { @@ -177,7 +177,7 @@ pub async fn messages_to_openai_json_text_only( }).collect(); if parts.is_empty() { - msg["content"] = serde_json::Value::Null; + msg["content"] = serde_json::json!(""); } else { msg["content"] = serde_json::json!(parts); }