fix: adjust default tool choice

This commit is contained in:
drbh 2024-07-18 00:57:02 +00:00
parent da82c63a4f
commit 35f8a88db5
2 changed files with 14 additions and 4 deletions

View File

@ -336,8 +336,14 @@ impl ToolGrammar {
tools: Option<Vec<Tool>>, tools: Option<Vec<Tool>>,
tool_choice: Option<ToolType>, tool_choice: Option<ToolType>,
) -> Result<Option<Tools>, InferError> { ) -> Result<Option<Tools>, InferError> {
if let Some((req_tools, tool_choice)) = tools.zip(tool_choice) { if let Some(req_tools) = tools {
// let tool_prompt = tool_prompt.unwrap_or_default(); let tool_choice = tool_choice
.map(|t| match t {
ToolType::FunctionName(name) if name == "auto" => ToolType::OneOf,
_ => t,
})
.unwrap_or_default();
let tools_to_use = match tool_choice { let tools_to_use = match tool_choice {
ToolType::FunctionName(name) => { ToolType::FunctionName(name) => {
vec![req_tools vec![req_tools

View File

@ -840,12 +840,16 @@ fn default_tool_prompt() -> Option<String> {
) )
} }
#[derive(Clone, Debug, Deserialize, PartialEq, Serialize, ToSchema)] #[derive(Clone, Default, Debug, Deserialize, PartialEq, Serialize, ToSchema)]
#[serde(untagged)] #[serde(untagged)]
pub enum ToolType { pub enum ToolType {
#[default]
#[serde(alias = "auto")]
OneOf, OneOf,
FunctionName(String), FunctionName(String),
Function { function: FunctionName }, Function {
function: FunctionName,
},
} }
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, ToSchema)] #[derive(Debug, Clone, PartialEq, Serialize, Deserialize, ToSchema)]