add OpenAI like tool_choice for named choice
This commit is contained in:
parent
3dbdf63ec5
commit
2285b0d63e
|
@ -2137,6 +2137,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.",
|
||||
|
|
|
@ -968,9 +968,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,
|
||||
|
@ -986,8 +995,10 @@ enum ToolTypeDeserializer {
|
|||
Null,
|
||||
String(String),
|
||||
ToolType(ToolType),
|
||||
TypedChoice(TypedChoice) //this is the OpenAI schema
|
||||
}
|
||||
|
||||
|
||||
impl From<ToolTypeDeserializer> for ToolChoice {
|
||||
fn from(value: ToolTypeDeserializer) -> Self {
|
||||
match value {
|
||||
|
@ -997,6 +1008,7 @@ impl From<ToolTypeDeserializer> 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)),
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue