Skip to content

Fixed duplicated arguments in tool-call-stream example #329

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion examples/tool-call-stream/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
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(),
Expand All @@ -92,7 +93,10 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
.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);
}
}
}
}
Expand Down