From 9d3d8b812cdafd58ea9ca572ed55a70bc25a6fb4 Mon Sep 17 00:00:00 2001 From: oudecheng <13802883547@139.com> Date: Wed, 13 May 2026 10:07:14 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E4=BC=98=E5=8C=96=E5=B7=A5=E5=85=B7?= =?UTF-8?q?=E5=8F=82=E6=95=B0=E5=BA=8F=E5=88=97=E5=8C=96=E9=80=BB=E8=BE=91?= =?UTF-8?q?=EF=BC=8C=E7=A1=AE=E4=BF=9D=E5=AD=97=E7=AC=A6=E4=B8=B2=E6=A0=BC?= =?UTF-8?q?=E5=BC=8F=E7=9A=84=E6=9C=89=E6=95=88=E6=80=A7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/providers/openai.rs | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/src/providers/openai.rs b/src/providers/openai.rs index cb30668..6a6d99a 100644 --- a/src/providers/openai.rs +++ b/src/providers/openai.rs @@ -128,12 +128,24 @@ impl OpenAIProvider { let normalized = self.normalize_tool_arguments(arguments); if self.uses_json_tool_arguments() { + // Model expects JSON object format normalized } else { + // Standard OpenAI format: arguments as JSON string + // But ensure we serialize valid JSON, not null match normalized { - Value::String(raw) => Value::String(raw), + Value::String(raw) => { + // If the string is already valid JSON, keep it as-is + // Otherwise, ensure it's a proper JSON string + if serde_json::from_str::(raw).is_ok() { + Value::String(raw) + } else { + // Invalid JSON string - wrap it as a proper JSON string + serde_json::to_string(&raw).unwrap_or_else(|_| "null".to_string()) + } + } value => Value::String( - serde_json::to_string(&value).unwrap_or_else(|_| "null".to_string()), + serde_json::to_string(&value).unwrap_or_else(|_| "{}".to_string()), ), } }