From 7ad4a624586b899049053051d5498679a189df01 Mon Sep 17 00:00:00 2001 From: drbh Date: Mon, 11 Mar 2024 13:26:06 +0100 Subject: [PATCH] fix: prefer tool call vector over object --- router/src/lib.rs | 6 +++--- router/src/server.rs | 8 ++++---- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/router/src/lib.rs b/router/src/lib.rs index 50d2cbf4..7b195cb9 100644 --- a/router/src/lib.rs +++ b/router/src/lib.rs @@ -433,7 +433,7 @@ impl ChatCompletion { created: u64, details: Details, return_logprobs: bool, - tool_calls: Option, + tool_calls: Option>, ) -> Self { Self { id: String::new(), @@ -764,7 +764,7 @@ pub(crate) struct ChatTemplateInputs<'a> { } #[derive(Clone, Deserialize, Serialize, ToSchema, Default, Debug)] -pub(crate) struct ToolCall { +pub(crate) struct ChatCompletionMessageToolCall { pub id: u32, pub r#type: String, pub function: FunctionDefinition, @@ -781,7 +781,7 @@ pub(crate) struct Message { #[schema(example = "\"David\"")] pub name: Option, #[serde(default, skip_serializing_if = "Option::is_none")] - pub tool_calls: Option, + pub tool_calls: Option>, } #[derive(Clone, Debug, Deserialize, ToSchema)] diff --git a/router/src/server.rs b/router/src/server.rs index c8e6017a..29e7165f 100644 --- a/router/src/server.rs +++ b/router/src/server.rs @@ -14,7 +14,7 @@ use crate::{ ChatRequest, CompatGenerateRequest, Completion, CompletionComplete, CompletionCompleteChunk, CompletionRequest, VertexRequest, VertexResponse, }; -use crate::{FunctionDefinition, FunctionRef, FunctionsMap, Properties, ToolCall, ToolType, Tools}; +use crate::{FunctionDefinition, FunctionRef, FunctionsMap, Properties, ChatCompletionMessageToolCall, ToolType, Tools}; use axum::extract::Extension; use axum::http::{HeaderMap, Method, StatusCode}; use axum::response::sse::{Event, KeepAlive, Sse}; @@ -942,7 +942,7 @@ async fn chat_completions( ) })?; - let tool_call = Some(ToolCall { + let tool_calls = vec![ChatCompletionMessageToolCall { id: 0, r#type: "function".to_string(), function: FunctionDefinition { @@ -963,8 +963,8 @@ async fn chat_completions( |f| Ok(f.clone()), )?, }, - }); - (tool_call, None) + }]; + (Some(tool_calls), None) } else { (None, Some(generation.generated_text)) };