From 209f841767d0d39c503b27dfa3028234e89d07ef Mon Sep 17 00:00:00 2001 From: David Holtz Date: Mon, 14 Oct 2024 16:44:54 +0000 Subject: [PATCH] fix: consolidate changes and remove old tool type --- docs/openapi.json | 23 +++++++++++++---------- router/src/lib.rs | 10 ++-------- 2 files changed, 15 insertions(+), 18 deletions(-) diff --git a/docs/openapi.json b/docs/openapi.json index 756afe1e..903f7426 100644 --- a/docs/openapi.json +++ b/docs/openapi.json @@ -2245,12 +2245,18 @@ "ToolType": { "oneOf": [ { - "type": "object", - "default": null, - "nullable": true + "type": "string", + "description": "Means the model can pick between generating a message or calling one or more tools.", + "enum": [ + "auto" + ] }, { - "type": "string" + "type": "string", + "description": "Means the model will not call any tool and instead generates a message.", + "enum": [ + "none" + ] }, { "type": "object", @@ -2262,13 +2268,10 @@ "$ref": "#/components/schemas/FunctionName" } } - }, - { - "type": "object", - "default": null, - "nullable": true } - ] + ], + "description": "Controls which (if any) tool is called by the model.", + "example": "auto" }, "Url": { "type": "object", diff --git a/router/src/lib.rs b/router/src/lib.rs index 6d342903..6ecc6b39 100644 --- a/router/src/lib.rs +++ b/router/src/lib.rs @@ -1036,8 +1036,7 @@ pub struct ToolChoice(pub Option); enum ToolTypeDeserializer { Null, String(String), - ToolType(ToolType), - TypedChoice(TypedChoice), //this is the OpenAI schema + ToolType(TypedChoice), } impl From for ToolChoice { @@ -1049,10 +1048,9 @@ impl From for ToolChoice { "auto" => ToolChoice(Some(ToolType::OneOf)), _ => ToolChoice(Some(ToolType::Function(FunctionName { name: s }))), }, - ToolTypeDeserializer::TypedChoice(TypedChoice::Function { function }) => { + ToolTypeDeserializer::ToolType(TypedChoice::Function { function }) => { ToolChoice(Some(ToolType::Function(function))) } - ToolTypeDeserializer::ToolType(tool_type) => ToolChoice(Some(tool_type)), } } } @@ -1682,10 +1680,6 @@ mod tests { let de_named: TestRequest = serde_json::from_str(named).unwrap(); assert_eq!(de_named.tool_choice, ref_choice); - let old_named = r#"{"tool_choice":{"function":{"name":"myfn"}}}"#; - let de_old_named: TestRequest = serde_json::from_str(old_named).unwrap(); - assert_eq!(de_old_named.tool_choice, ref_choice); - let openai_named = r#"{"tool_choice":{"type":"function","function":{"name":"myfn"}}}"#; let de_openai_named: TestRequest = serde_json::from_str(openai_named).unwrap();