Fix tool call response to adhere to OpenAI spec

This commit is contained in:
datta0 2025-01-24 07:22:11 +00:00
parent d9dda11726
commit 3495248d87

View File

@ -1371,7 +1371,7 @@ pub(crate) async fn chat_completions(
system_fingerprint.clone(), system_fingerprint.clone(),
model_id.clone(), model_id.clone(),
); );
yield Ok::<Event, Infallible>(event); yield Ok::<Event, Infallible>(event);
} }
} }
@ -1432,13 +1432,21 @@ pub(crate) async fn chat_completions(
(None, Some(content_message)) (None, Some(content_message))
} }
_ => { _ => {
let arguments_string = serde_json::to_string(&arguments).map_err(|e| {
InferError::ToolError(format!(
"Failed to serialize arguments to string: {}",
e
))
})?;
println!("Arguments: {:?}", arguments);
println!("Arguments String: {:?}", arguments_string);
let tool_calls = vec![ToolCall { let tool_calls = vec![ToolCall {
id: "0".to_string(), id: format!("{:09}", 0),
r#type: "function".to_string(), r#type: "function".to_string(),
function: FunctionDefinition { function: FunctionDefinition {
description: None, description: None,
name, name,
arguments, arguments: Value::String(arguments_string), // Serialize to string here
}, },
}]; }];
(Some(tool_calls), None) (Some(tool_calls), None)