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
fccac7d1
Unverified
Commit
fccac7d1
authored
Oct 08, 2025
by
Chang Su
Committed by
GitHub
Oct 08, 2025
Browse files
[router][grpc] Add dependencies in Cargo.toml to support chat template rendering (#11342)
parent
7ac6b900
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
5 additions
and
17 deletions
+5
-17
sgl-router/Cargo.toml
sgl-router/Cargo.toml
+1
-1
sgl-router/src/tool_parser/parsers/json_parser.rs
sgl-router/src/tool_parser/parsers/json_parser.rs
+2
-7
sgl-router/src/tool_parser/parsers/llama_parser.rs
sgl-router/src/tool_parser/parsers/llama_parser.rs
+2
-8
sgl-router/tests/tool_parser_llama.rs
sgl-router/tests/tool_parser_llama.rs
+0
-1
No files found.
sgl-router/Cargo.toml
View file @
fccac7d1
...
...
@@ -57,7 +57,7 @@ tokio-stream = { version = "0.1", features = ["sync"] }
anyhow
=
"1.0"
tokenizers
=
{
version
=
"0.22.0"
}
tiktoken-rs
=
{
version
=
"0.7.0"
}
minijinja
=
{
version
=
"2.0"
,
features
=
["unstable_machinery"]
}
minijinja
=
{
version
=
"2.0"
,
features
=
[
"unstable_machinery"
,
"json"
,
"builtins"
]
}
rustls
=
{
version
=
"0.23"
,
default-features
=
false
,
features
=
[
"ring"
,
"std"
]
}
hf-hub
=
{
version
=
"0.4.3"
,
features
=
["tokio"]
}
rmcp
=
{
version
=
"0.6.3"
,
features
=
[
"client"
,
"server"
,
...
...
sgl-router/src/tool_parser/parsers/json_parser.rs
View file @
fccac7d1
...
...
@@ -174,11 +174,6 @@ impl JsonParser {
Ok
(
tools
)
}
/// Check if text contains tool calls
fn
has_tool_call
(
&
self
,
text
:
&
str
)
->
bool
{
text
.contains
(
'['
)
||
text
.contains
(
'{'
)
}
}
impl
Default
for
JsonParser
{
...
...
@@ -216,7 +211,7 @@ impl ToolParser for JsonParser {
let
current_text
=
&
self
.buffer
.clone
();
// Check if current_text has tool_call
let
has_tool_start
=
self
.has_tool_
call
(
current_text
)
let
has_tool_start
=
self
.has_tool_
markers
(
current_text
)
||
(
self
.current_tool_id
>=
0
&&
current_text
.starts_with
(
self
.tool_call_separator
));
if
!
has_tool_start
{
...
...
@@ -263,7 +258,7 @@ impl ToolParser for JsonParser {
fn
has_tool_markers
(
&
self
,
text
:
&
str
)
->
bool
{
let
trimmed
=
text
.trim
();
(
trimmed
.starts_with
(
'['
)
||
trimmed
.starts_with
(
'{'
)
)
&&
trimmed
.contains
(
r#""name""#
)
trimmed
.starts_with
(
'['
)
||
trimmed
.starts_with
(
'{'
)
}
fn
get_unstreamed_tool_args
(
&
self
)
->
Option
<
Vec
<
ToolCallItem
>>
{
...
...
sgl-router/src/tool_parser/parsers/llama_parser.rs
View file @
fccac7d1
...
...
@@ -121,11 +121,6 @@ impl LlamaParser {
Ok
(
all_tools
)
}
/// Check if text has tool call
fn
has_tool_call
(
&
self
,
text
:
&
str
)
->
bool
{
text
.contains
(
"<|python_tag|>"
)
||
text
.contains
(
'{'
)
}
}
impl
Default
for
LlamaParser
{
...
...
@@ -184,7 +179,7 @@ impl ToolParser for LlamaParser {
let
current_text
=
&
self
.buffer
.clone
();
// Check if current_text has tool_call
let
has_tool_start
=
self
.has_tool_
call
(
current_text
)
let
has_tool_start
=
self
.has_tool_
markers
(
current_text
)
||
(
self
.current_tool_id
>=
0
&&
current_text
.starts_with
(
self
.tool_call_separator
));
if
!
has_tool_start
{
...
...
@@ -230,8 +225,7 @@ impl ToolParser for LlamaParser {
fn
has_tool_markers
(
&
self
,
text
:
&
str
)
->
bool
{
// Llama format if contains python_tag or starts with JSON object
text
.contains
(
"<|python_tag|>"
)
||
(
text
.trim_start
()
.starts_with
(
'{'
)
&&
text
.contains
(
r#""name""#
))
text
.contains
(
"<|python_tag|>"
)
||
text
.trim_start
()
.starts_with
(
'{'
)
}
fn
get_unstreamed_tool_args
(
&
self
)
->
Option
<
Vec
<
crate
::
tool_parser
::
types
::
ToolCallItem
>>
{
...
...
sgl-router/tests/tool_parser_llama.rs
View file @
fccac7d1
...
...
@@ -119,7 +119,6 @@ async fn test_llama_format_detection() {
assert
!
(
parser
.has_tool_markers
(
r#"<|python_tag|>{"name": "test"}"#
));
assert
!
(
parser
.has_tool_markers
(
r#"{"name": "test", "parameters": {}}"#
));
assert
!
(
!
parser
.has_tool_markers
(
"plain text"
));
assert
!
(
!
parser
.has_tool_markers
(
r#"{"key": "value"}"#
));
// No name field
}
#[tokio::test]
...
...
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