From 3495248d8743b3b2a20314e5b9af2c045fec2049 Mon Sep 17 00:00:00 2001 From: datta0 Date: Fri, 24 Jan 2025 07:22:11 +0000 Subject: [PATCH] Fix tool call response to adhere to OpenAI spec --- router/src/server.rs | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/router/src/server.rs b/router/src/server.rs index aef0f812..29ceb8e6 100644 --- a/router/src/server.rs +++ b/router/src/server.rs @@ -1371,7 +1371,7 @@ pub(crate) async fn chat_completions( system_fingerprint.clone(), model_id.clone(), ); - + yield Ok::(event); } } @@ -1432,13 +1432,21 @@ pub(crate) async fn chat_completions( (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 { - id: "0".to_string(), + id: format!("{:09}", 0), r#type: "function".to_string(), function: FunctionDefinition { description: None, name, - arguments, + arguments: Value::String(arguments_string), // Serialize to string here }, }]; (Some(tool_calls), None)