From 2c172a2da72e4a4383d19c1a60b375f4c03a5aa2 Mon Sep 17 00:00:00 2001 From: David Holtz Date: Mon, 14 Oct 2024 14:26:45 +0000 Subject: [PATCH] fix: run linter and bump api docs --- docs/openapi.json | 35 +++++++---------------------------- router/src/lib.rs | 15 ++++++++------- 2 files changed, 15 insertions(+), 35 deletions(-) diff --git a/docs/openapi.json b/docs/openapi.json index 280754bc..756afe1e 100644 --- a/docs/openapi.json +++ b/docs/openapi.json @@ -2245,18 +2245,12 @@ "ToolType": { "oneOf": [ { - "type": "string", - "description": "Means the model can pick between generating a message or calling one or more tools.", - "enum": [ - "auto" - ] + "type": "object", + "default": null, + "nullable": true }, { - "type": "string", - "description": "Means the model will not call any tool and instead generates a message.", - "enum": [ - "none" - ] + "type": "string" }, { "type": "object", @@ -2271,25 +2265,10 @@ }, { "type": "object", - "required": [ - "type", - "function" - ], - "properties": { - "type": { - "type": "string", - "enum": [ - "function" - ] - }, - "function": { - "$ref": "#/components/schemas/FunctionName" - } - } + "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 c4189904..6d342903 100644 --- a/router/src/lib.rs +++ b/router/src/lib.rs @@ -1015,12 +1015,11 @@ pub enum ToolType { Function(FunctionName), } - #[derive(Clone, Debug, Deserialize, PartialEq, Serialize)] #[serde(tag = "type")] pub enum TypedChoice { #[serde(rename = "function")] - Function{function: FunctionName}, + Function { function: FunctionName }, } #[derive(Debug, Clone, PartialEq, Serialize, Deserialize, ToSchema)] @@ -1038,10 +1037,9 @@ enum ToolTypeDeserializer { Null, String(String), ToolType(ToolType), - TypedChoice(TypedChoice) //this is the OpenAI schema + TypedChoice(TypedChoice), //this is the OpenAI schema } - impl From for ToolChoice { fn from(value: ToolTypeDeserializer) -> Self { match value { @@ -1051,7 +1049,9 @@ 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::TypedChoice(TypedChoice::Function { function }) => { + ToolChoice(Some(ToolType::Function(function))) + } ToolTypeDeserializer::ToolType(tool_type) => ToolChoice(Some(tool_type)), } } @@ -1661,7 +1661,6 @@ mod tests { #[test] fn tool_choice_formats() { - #[derive(Deserialize)] struct TestRequest { tool_choice: ToolChoice, @@ -1675,7 +1674,9 @@ mod tests { let de_auto: TestRequest = serde_json::from_str(auto).unwrap(); assert_eq!(de_auto.tool_choice, ToolChoice(Some(ToolType::OneOf))); - let ref_choice = ToolChoice(Some(ToolType::Function(FunctionName { name: "myfn".to_string() }))); + let ref_choice = ToolChoice(Some(ToolType::Function(FunctionName { + name: "myfn".to_string(), + }))); let named = r#"{"tool_choice":"myfn"}"#; let de_named: TestRequest = serde_json::from_str(named).unwrap();