Skip to content

Commit

Permalink
fix: consolidate changes and remove old tool type
Browse files Browse the repository at this point in the history
  • Loading branch information
drbh committed Oct 14, 2024
1 parent a071ccd commit 72a0305
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 18 deletions.
23 changes: 13 additions & 10 deletions docs/openapi.json
Original file line number Diff line number Diff line change
Expand Up @@ -2114,12 +2114,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",
Expand All @@ -2131,13 +2137,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",
Expand Down
10 changes: 2 additions & 8 deletions router/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -993,8 +993,7 @@ pub struct ToolChoice(pub Option<ToolType>);
enum ToolTypeDeserializer {
Null,
String(String),
ToolType(ToolType),
TypedChoice(TypedChoice), //this is the OpenAI schema
ToolType(TypedChoice),
}

impl From<ToolTypeDeserializer> for ToolChoice {
Expand All @@ -1006,10 +1005,9 @@ impl From<ToolTypeDeserializer> 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)),
}
}
}
Expand Down Expand Up @@ -1640,10 +1638,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();

Expand Down

0 comments on commit 72a0305

Please sign in to comment.