[Rust Frontend] Tolerate whitespace before the outer brace in JSON tool-call parsers (#48034)
Signed-off-by: Tahsin Tunan <tahsintunan@gmail.com>
This commit is contained in:
@@ -451,6 +451,57 @@ mod tests {
|
||||
output
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn unified_stream_parses_formatted_tool_call_without_latch() {
|
||||
use vllm_parser::tool::{HermesToolParser, ToolParser as _};
|
||||
|
||||
let hermes = HermesToolParser::create(&[]).unwrap();
|
||||
let parser = vllm_parser::unified::CombinedParser::new(None, Some(hermes));
|
||||
|
||||
// Regression guard: a formatted call (space before the outer `}`) must not
|
||||
// trip the parse-error latch that turns it and every later call into text.
|
||||
let d1 = decoded_delta(
|
||||
r#"<tool_call>{"name":"get_weather","arguments":{"location":"Paris"} }</tool_call>"#,
|
||||
);
|
||||
let d2 = finished_delta(
|
||||
r#"<tool_call>{"name":"get_time","arguments":{"tz":"UTC"}}</tool_call>"#,
|
||||
);
|
||||
|
||||
let stream = stream::iter(vec![d1, d2].into_iter().map(Ok));
|
||||
let events = unified_event_stream(stream, Box::new(parser))
|
||||
.collect::<Vec<_>>()
|
||||
.await
|
||||
.into_iter()
|
||||
.collect::<crate::Result<Vec<_>>>()
|
||||
.unwrap();
|
||||
|
||||
let names: Vec<&str> = events
|
||||
.iter()
|
||||
.filter_map(|event| match event {
|
||||
AssistantEvent::ToolCallStart { name, .. } => Some(name.as_str()),
|
||||
_ => None,
|
||||
})
|
||||
.collect();
|
||||
assert_eq!(names, ["get_weather", "get_time"]);
|
||||
|
||||
let text_leaks = events
|
||||
.iter()
|
||||
.filter(|event| {
|
||||
matches!(
|
||||
event,
|
||||
AssistantEvent::TextDelta {
|
||||
kind: AssistantBlockKind::Text,
|
||||
..
|
||||
}
|
||||
)
|
||||
})
|
||||
.count();
|
||||
assert_eq!(
|
||||
text_leaks, 0,
|
||||
"formatted tool call leaked into text: {events:#?}"
|
||||
);
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn unified_stream_emits_reasoning_only_deltas() {
|
||||
let events = collect(
|
||||
|
||||
Reference in New Issue
Block a user