From 2cf69c1524d6ec8dcc823a88f7ac40c8c641e9e9 Mon Sep 17 00:00:00 2001 From: Martin Mende Date: Tue, 4 Feb 2025 08:07:24 +0100 Subject: [PATCH] Fixed duplicated arguments --- examples/tool-call-stream/src/main.rs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/examples/tool-call-stream/src/main.rs b/examples/tool-call-stream/src/main.rs index 230ee9a3..72264b6e 100644 --- a/examples/tool-call-stream/src/main.rs +++ b/examples/tool-call-stream/src/main.rs @@ -69,6 +69,7 @@ async fn main() -> Result<(), Box> { let tool_call_data = tool_call_chunk.clone(); let mut states_lock = states.lock().await; + let tool_call_existed = states_lock.contains_key(&key); let state = states_lock.entry(key).or_insert_with(|| { ChatCompletionMessageToolCall { id: tool_call_data.id.clone().unwrap_or_default(), @@ -92,7 +93,10 @@ async fn main() -> Result<(), Box> { .as_ref() .and_then(|f| f.arguments.as_ref()) { - state.function.arguments.push_str(arguments); + // Only update the arguments for existing tool calls because when inserting a new tool call, the arguments are already set + if tool_call_existed { + state.function.arguments.push_str(arguments); + } } } }