Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
change
sglang
Commits
c7962868
Unverified
Commit
c7962868
authored
Oct 16, 2025
by
Chang Su
Committed by
GitHub
Oct 16, 2025
Browse files
[router] Fix tool_choice normalization in ChatCompletionRequest and fix ut (#11731)
parent
4f24ab17
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
8 additions
and
49 deletions
+8
-49
sgl-router/src/protocols/chat.rs
sgl-router/src/protocols/chat.rs
+8
-7
sgl-router/tests/spec/rerank.rs
sgl-router/tests/spec/rerank.rs
+0
-42
No files found.
sgl-router/src/protocols/chat.rs
View file @
c7962868
...
...
@@ -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)
}
}
}
...
...
sgl-router/tests/spec/rerank.rs
View file @
c7962868
...
...
@@ -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
());
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment