Unverified Commit c7962868 authored by Chang Su's avatar Chang Su Committed by GitHub
Browse files

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

parent 4f24ab17
......@@ -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)
}
}
}
......
......@@ -230,45 +230,6 @@ fn test_rerank_response_serialization() {
assert_eq!(deserialized.object, response.object);
}
#[test]
fn test_rerank_response_sort_by_score() {
let results = vec![
RerankResult {
score: 0.6,
document: Some("doc2".to_string()),
index: 1,
meta_info: None,
},
RerankResult {
score: 0.8,
document: Some("doc1".to_string()),
index: 0,
meta_info: None,
},
RerankResult {
score: 0.4,
document: Some("doc3".to_string()),
index: 2,
meta_info: None,
},
];
let mut response = RerankResponse::new(
results,
"test-model".to_string(),
Some(StringOrArray::String("req-123".to_string())),
);
response.sort_by_score();
assert_eq!(response.results[0].score, 0.8);
assert_eq!(response.results[0].index, 0);
assert_eq!(response.results[1].score, 0.6);
assert_eq!(response.results[1].index, 1);
assert_eq!(response.results[2].score, 0.4);
assert_eq!(response.results[2].index, 2);
}
#[test]
fn test_rerank_response_apply_top_k() {
let results = vec![
......@@ -589,9 +550,6 @@ fn test_full_rerank_workflow() {
// Create response
let mut response = RerankResponse::new(results, request.model.clone(), request.rid.clone());
// Sort by score
response.sort_by_score();
// Apply top_k
response.apply_top_k(request.effective_top_k());
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment