[router][grpc] Support tool call parser in streaming (#11160)

This commit is contained in:
Chang Su
2025-10-02 03:18:50 -07:00
committed by GitHub
parent 5e786cca3a
commit b658be6f6a
38 changed files with 3086 additions and 2245 deletions

View File

@@ -1,6 +1,9 @@
//! Step3 Parser Integration Tests
use sglang_router_rs::tool_parser::{ParseState, Step3Parser, StreamResult, ToolParser};
use sglang_router_rs::tool_parser::{Step3Parser, ToolParser};
mod common;
use common::create_test_tools;
#[tokio::test]
async fn test_step3_complete_parsing() {
@@ -72,8 +75,9 @@ async fn test_step3_type_conversion() {
#[tokio::test]
async fn test_step3_streaming() {
let parser = Step3Parser::new();
let mut state = ParseState::new();
let mut parser = Step3Parser::new();
let tools = create_test_tools();
// Simulate streaming chunks
let chunks = vec![
@@ -86,26 +90,20 @@ async fn test_step3_streaming() {
"\n<tool_calls_end>",
];
let mut found_name = false;
let mut found_complete = false;
for chunk in chunks {
let result = parser.parse_incremental(chunk, &mut state).await.unwrap();
let result = parser.parse_incremental(chunk, &tools).await.unwrap();
match result {
StreamResult::ToolName { name, .. } => {
if !result.calls.is_empty() {
if let Some(name) = &result.calls[0].name {
assert_eq!(name, "calc");
found_name = true;
}
StreamResult::ToolComplete(tool) => {
assert_eq!(tool.function.name, "calc");
found_complete = true;
}
_ => {}
}
}
assert!(found_name || found_complete);
assert!(found_complete);
}
#[test]