Skip to content

Commit 2f81ad8

Browse files
committed
Log warnings when parser is not found instead of panic
1 parent 612ccb7 commit 2f81ad8

1 file changed

Lines changed: 25 additions & 12 deletions

File tree

sgl-router/src/routers/grpc/streaming.rs

Lines changed: 25 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ use axum::{body::Body, http::StatusCode};
88
use bytes::Bytes;
99
use http::header::{HeaderValue, CONTENT_TYPE};
1010
use serde_json::{json, Value};
11+
use std::collections::hash_map::Entry;
1112
use std::collections::HashMap;
1213
use std::io;
1314
use std::sync::Arc;
@@ -963,15 +964,21 @@ impl StreamingProcessor {
963964
system_fingerprint: Option<&str>,
964965
) -> (String, Option<ChatCompletionStreamResponse>, bool) {
965966
// Create fresh parser for this index (not pooled, to avoid state pollution)
966-
reasoning_parsers.entry(index).or_insert_with(|| {
967-
let parser = utils::create_reasoning_parser(
967+
// If no parser is found, don't insert anything and skip reasoning parsing
968+
if let Entry::Vacant(e) = reasoning_parsers.entry(index) {
969+
if let Some(parser) = utils::create_reasoning_parser(
968970
&self.reasoning_parser_factory,
969971
self.configured_reasoning_parser.as_ref(),
970972
model,
971-
)
972-
.expect("Failed to create reasoning parser");
973-
Arc::new(tokio::sync::Mutex::new(parser))
974-
});
973+
) {
974+
e.insert(Arc::new(tokio::sync::Mutex::new(parser)));
975+
} else {
976+
warn!(
977+
"No reasoning parser found for model '{}', skipping reasoning parsing",
978+
model
979+
);
980+
}
981+
}
975982

976983
if let Some(pooled_parser) = reasoning_parsers.get(&index) {
977984
let (parse_result, in_reasoning) = {
@@ -1039,15 +1046,21 @@ impl StreamingProcessor {
10391046
let mut chunks = Vec::new();
10401047

10411048
// Create fresh parser for this index (not pooled, to avoid state pollution)
1042-
tool_parsers.entry(index).or_insert_with(|| {
1043-
let parser = utils::create_tool_parser(
1049+
// If no parser is found, don't insert anything and skip tool parsing
1050+
if let Entry::Vacant(e) = tool_parsers.entry(index) {
1051+
if let Some(parser) = utils::create_tool_parser(
10441052
&self.tool_parser_factory,
10451053
self.configured_tool_parser.as_ref(),
10461054
model,
1047-
)
1048-
.expect("Failed to create tool parser");
1049-
Arc::new(tokio::sync::Mutex::new(parser))
1050-
});
1055+
) {
1056+
e.insert(Arc::new(tokio::sync::Mutex::new(parser)));
1057+
} else {
1058+
warn!(
1059+
"No tool parser found for model '{}', skipping tool call parsing",
1060+
model
1061+
);
1062+
}
1063+
}
10511064

10521065
if let Some(pooled_parser) = tool_parsers.get(&index) {
10531066
let mut parser = pooled_parser.lock().await;

0 commit comments

Comments
 (0)