Skip to content

Commit 330b05a

Browse files
CatherineSuech-tiger1
authored andcommitted
[router][grpc] Add dependencies in Cargo.toml to support chat template rendering (sgl-project#11342)
1 parent 5b25543 commit 330b05a

File tree

4 files changed

+5
-17
lines changed

4 files changed

+5
-17
lines changed

sgl-router/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ tokio-stream = { version = "0.1", features = ["sync"] }
5757
anyhow = "1.0"
5858
tokenizers = { version = "0.22.0" }
5959
tiktoken-rs = { version = "0.7.0" }
60-
minijinja = { version = "2.0", features = ["unstable_machinery"] }
60+
minijinja = { version = "2.0", features = ["unstable_machinery", "json", "builtins"] }
6161
rustls = { version = "0.23", default-features = false, features = ["ring", "std"] }
6262
hf-hub = { version = "0.4.3", features = ["tokio"] }
6363
rmcp = { version = "0.6.3", features = ["client", "server",

sgl-router/src/tool_parser/parsers/json_parser.rs

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -174,11 +174,6 @@ impl JsonParser {
174174

175175
Ok(tools)
176176
}
177-
178-
/// Check if text contains tool calls
179-
fn has_tool_call(&self, text: &str) -> bool {
180-
text.contains('[') || text.contains('{')
181-
}
182177
}
183178

184179
impl Default for JsonParser {
@@ -216,7 +211,7 @@ impl ToolParser for JsonParser {
216211
let current_text = &self.buffer.clone();
217212

218213
// Check if current_text has tool_call
219-
let has_tool_start = self.has_tool_call(current_text)
214+
let has_tool_start = self.has_tool_markers(current_text)
220215
|| (self.current_tool_id >= 0 && current_text.starts_with(self.tool_call_separator));
221216

222217
if !has_tool_start {
@@ -263,7 +258,7 @@ impl ToolParser for JsonParser {
263258

264259
fn has_tool_markers(&self, text: &str) -> bool {
265260
let trimmed = text.trim();
266-
(trimmed.starts_with('[') || trimmed.starts_with('{')) && trimmed.contains(r#""name""#)
261+
trimmed.starts_with('[') || trimmed.starts_with('{')
267262
}
268263

269264
fn get_unstreamed_tool_args(&self) -> Option<Vec<ToolCallItem>> {

sgl-router/src/tool_parser/parsers/llama_parser.rs

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -121,11 +121,6 @@ impl LlamaParser {
121121

122122
Ok(all_tools)
123123
}
124-
125-
/// Check if text has tool call
126-
fn has_tool_call(&self, text: &str) -> bool {
127-
text.contains("<|python_tag|>") || text.contains('{')
128-
}
129124
}
130125

131126
impl Default for LlamaParser {
@@ -184,7 +179,7 @@ impl ToolParser for LlamaParser {
184179
let current_text = &self.buffer.clone();
185180

186181
// Check if current_text has tool_call
187-
let has_tool_start = self.has_tool_call(current_text)
182+
let has_tool_start = self.has_tool_markers(current_text)
188183
|| (self.current_tool_id >= 0 && current_text.starts_with(self.tool_call_separator));
189184

190185
if !has_tool_start {
@@ -230,8 +225,7 @@ impl ToolParser for LlamaParser {
230225

231226
fn has_tool_markers(&self, text: &str) -> bool {
232227
// Llama format if contains python_tag or starts with JSON object
233-
text.contains("<|python_tag|>")
234-
|| (text.trim_start().starts_with('{') && text.contains(r#""name""#))
228+
text.contains("<|python_tag|>") || text.trim_start().starts_with('{')
235229
}
236230

237231
fn get_unstreamed_tool_args(&self) -> Option<Vec<crate::tool_parser::types::ToolCallItem>> {

sgl-router/tests/tool_parser_llama.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,6 @@ async fn test_llama_format_detection() {
119119
assert!(parser.has_tool_markers(r#"<|python_tag|>{"name": "test"}"#));
120120
assert!(parser.has_tool_markers(r#"{"name": "test", "parameters": {}}"#));
121121
assert!(!parser.has_tool_markers("plain text"));
122-
assert!(!parser.has_tool_markers(r#"{"key": "value"}"#)); // No name field
123122
}
124123

125124
#[tokio::test]

0 commit comments

Comments
 (0)