diff options
| author | sigoden <sigoden@gmail.com> | 2025-03-05 08:38:35 +0800 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-03-05 08:38:35 +0800 |
| commit | d7a9244d678767ac1103c1e38282b158cd6b3fe5 (patch) | |
| tree | 3ee2ac1023747ed983459ef59f20253bddd15ee0 | |
| parent | 26034f5103f50559f3ee274026669799725441a4 (diff) | |
| download | aichat-d7a9244d678767ac1103c1e38282b158cd6b3fe5.tar.gz | |
fix: openai-compatible handles empty tool call arguments (#1217)
| -rw-r--r-- | src/client/openai.rs | 6 |
1 files changed, 6 insertions, 0 deletions
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<bool> { 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}'") })?; |
