diff --git a/docs/openapi.json b/docs/openapi.json index 903f7426..280754bc 100644 --- a/docs/openapi.json +++ b/docs/openapi.json @@ -2268,6 +2268,24 @@ "$ref": "#/components/schemas/FunctionName" } } + }, + { + "type": "object", + "required": [ + "type", + "function" + ], + "properties": { + "type": { + "type": "string", + "enum": [ + "function" + ] + }, + "function": { + "$ref": "#/components/schemas/FunctionName" + } + } } ], "description": "Controls which (if any) tool is called by the model.", diff --git a/router/src/lib.rs b/router/src/lib.rs index a5613f89..52a8a64a 100644 --- a/router/src/lib.rs +++ b/router/src/lib.rs @@ -1011,9 +1011,18 @@ pub enum ToolType { NoTool, /// Forces the model to call a specific tool. #[schema(rename = "function")] + #[serde(alias = "function")] Function(FunctionName), } + +#[derive(Clone, Debug, Deserialize, PartialEq, Serialize)] +#[serde(tag = "type")] +pub enum TypedChoice { + #[serde(rename = "function")] + Function{function: FunctionName}, +} + #[derive(Debug, Clone, PartialEq, Serialize, Deserialize, ToSchema)] pub struct FunctionName { pub name: String, @@ -1029,8 +1038,10 @@ enum ToolTypeDeserializer { Null, String(String), ToolType(ToolType), + TypedChoice(TypedChoice) //this is the OpenAI schema } + impl From for ToolChoice { fn from(value: ToolTypeDeserializer) -> Self { match value { @@ -1040,6 +1051,7 @@ impl From for ToolChoice { "auto" => ToolChoice(Some(ToolType::OneOf)), _ => ToolChoice(Some(ToolType::Function(FunctionName { name: s }))), }, + ToolTypeDeserializer::TypedChoice(TypedChoice::Function{function}) => ToolChoice(Some(ToolType::Function(function))), ToolTypeDeserializer::ToolType(tool_type) => ToolChoice(Some(tool_type)), } }