From d7a9244d678767ac1103c1e38282b158cd6b3fe5 Mon Sep 17 00:00:00 2001 From: sigoden Date: Wed, 5 Mar 2025 08:38:35 +0800 Subject: fix: openai-compatible handles empty tool call arguments (#1217) --- src/client/openai.rs | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'src') diff --git a/src/client/openai.rs b/src/client/openai.rs index e5f4d23..ab12b1a 100644 --- a/src/client/openai.rs +++ b/src/client/openai.rs @@ -110,6 +110,9 @@ pub async fn openai_chat_completions_streaming( let handle = |message: SseMmessage| -> Result { if message.data == "[DONE]" { if !function_name.is_empty() { + if function_arguments.is_empty() { + function_arguments = String::from("{}"); + } let arguments: Value = function_arguments.parse().with_context(|| { format!("Tool call '{function_name}' have non-JSON arguments '{function_arguments}'") })?; @@ -153,6 +156,9 @@ pub async fn openai_chat_completions_streaming( let maybe_call_id = format!("{}/{}", id.unwrap_or_default(), index.unwrap_or_default()); if maybe_call_id != call_id && maybe_call_id.len() >= call_id.len() { if !function_name.is_empty() { + if function_arguments.is_empty() { + function_arguments = String::from("{}"); + } let arguments: Value = function_arguments.parse().with_context(|| { format!("Tool call '{function_name}' have non-JSON arguments '{function_arguments}'") })?; -- cgit v1.2.3