[router] Fix tool_choice normalization in ChatCompletionRequest and fix ut (#11731)

This commit is contained in:
Chang Su
2025-10-16 14:20:13 -07:00
committed by GitHub
parent 4f24ab1718
commit c7962868c1
2 changed files with 8 additions and 49 deletions

View File

@@ -531,13 +531,14 @@ impl Normalizable for ChatCompletionRequest {
// Apply tool_choice defaults
if self.tool_choice.is_none() {
let has_tools = self.tools.as_ref().is_some_and(|t| !t.is_empty());
self.tool_choice = if has_tools {
Some(ToolChoice::Value(ToolChoiceValue::Auto))
} else {
Some(ToolChoice::Value(ToolChoiceValue::None))
};
if let Some(tools) = &self.tools {
self.tool_choice = if !tools.is_empty() {
Some(ToolChoice::Value(ToolChoiceValue::Auto))
} else {
Some(ToolChoice::Value(ToolChoiceValue::None))
};
}
// If tools is None, leave tool_choice as None (don't set it)
}
}
}