Update ToolType input schema

This commit is contained in:
Wauplin 2024-10-02 12:01:10 +02:00
parent 5b6b74e21d
commit aae6db9cd0
No known key found for this signature in database
GPG Key ID: 9838FE02BECE1A02
3 changed files with 26 additions and 18 deletions

View File

@ -2114,12 +2114,18 @@
"ToolType": { "ToolType": {
"oneOf": [ "oneOf": [
{ {
"type": "object", "type": "string",
"default": null, "description": "Means the model can pick between generating a message or calling one or more tools.",
"nullable": true "enum": [
"auto"
]
}, },
{ {
"type": "string" "type": "string",
"description": "Means the model will not call any tool and instead generates a message.",
"enum": [
"none"
]
}, },
{ {
"type": "object", "type": "object",
@ -2131,13 +2137,10 @@
"$ref": "#/components/schemas/FunctionName" "$ref": "#/components/schemas/FunctionName"
} }
} }
},
{
"type": "object",
"default": null,
"nullable": true
} }
] ],
"description": "Controls which (if any) tool is called by the model.",
"example": "auto"
}, },
"Url": { "Url": {
"type": "object", "type": "object",

View File

@ -53,10 +53,7 @@ impl ToolGrammar {
// if tools are provided and no tool_choice we default to the OneOf // if tools are provided and no tool_choice we default to the OneOf
let tools_to_use = match tool_choice { let tools_to_use = match tool_choice {
ToolType::FunctionName(name) => { ToolType::Function ( function ) => {
vec![Self::find_tool_by_name(&tools, &name)?]
}
ToolType::Function { function } => {
vec![Self::find_tool_by_name(&tools, &function.name)?] vec![Self::find_tool_by_name(&tools, &function.name)?]
} }
ToolType::OneOf => tools.clone(), ToolType::OneOf => tools.clone(),

View File

@ -957,12 +957,18 @@ pub fn default_tool_prompt() -> String {
} }
#[derive(Clone, Debug, Deserialize, PartialEq, Serialize, ToSchema)] #[derive(Clone, Debug, Deserialize, PartialEq, Serialize, ToSchema)]
#[serde(untagged)] #[schema(example = "auto")]
/// Controls which (if any) tool is called by the model.
pub enum ToolType { pub enum ToolType {
/// Means the model can pick between generating a message or calling one or more tools.
#[schema(rename = "auto")]
OneOf, OneOf,
FunctionName(String), /// Means the model will not call any tool and instead generates a message.
Function { function: FunctionName }, #[schema(rename = "none")]
NoTool, NoTool,
/// Forces the model to call a specific tool.
#[schema(rename = "function")]
Function(FunctionName),
} }
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, ToSchema)] #[derive(Debug, Clone, PartialEq, Serialize, Deserialize, ToSchema)]
@ -987,7 +993,9 @@ impl From<ToolTypeDeserializer> for ToolChoice {
ToolTypeDeserializer::String(s) => match s.as_str() { ToolTypeDeserializer::String(s) => match s.as_str() {
"none" => ToolChoice(Some(ToolType::NoTool)), "none" => ToolChoice(Some(ToolType::NoTool)),
"auto" => ToolChoice(Some(ToolType::OneOf)), "auto" => ToolChoice(Some(ToolType::OneOf)),
_ => ToolChoice(Some(ToolType::FunctionName(s))), _ => ToolChoice(Some(ToolType::Function(FunctionName {
name: s
} ))),
}, },
ToolTypeDeserializer::ToolType(tool_type) => ToolChoice(Some(tool_type)), ToolTypeDeserializer::ToolType(tool_type) => ToolChoice(Some(tool_type)),
} }