[router][tool call] Support normal content extraction before tool call (streaming) (#11038)
This commit is contained in:
@@ -190,7 +190,18 @@ impl ToolParser for QwenParser {
|
||||
|
||||
// Check if we have the start marker
|
||||
if !self.has_tool_markers(&state.buffer) {
|
||||
return Ok(StreamResult::Incomplete);
|
||||
// No tool markers detected - return all buffered content as normal text
|
||||
let normal_text = std::mem::take(&mut state.buffer);
|
||||
return Ok(StreamResult::NormalText(normal_text));
|
||||
}
|
||||
|
||||
// Check for text before tool markers and extract it as normal text
|
||||
if let Some(marker_pos) = state.buffer.find("<tool_call>") {
|
||||
if marker_pos > 0 {
|
||||
// We have text before the tool marker - extract it as normal text
|
||||
let normal_text: String = state.buffer.drain(..marker_pos).collect();
|
||||
return Ok(StreamResult::NormalText(normal_text));
|
||||
}
|
||||
}
|
||||
|
||||
// Find start and end positions
|
||||
@@ -212,7 +223,12 @@ impl ToolParser for QwenParser {
|
||||
}
|
||||
}
|
||||
Err(_) => {
|
||||
// JSON parsing failed, might be incomplete
|
||||
// JSON parsing failed, might be incomplete or malformed
|
||||
// If we have what looks like a complete tool call block, treat as normal text
|
||||
if state.buffer[start_pos..end_pos].contains("\n</tool_call>") {
|
||||
let malformed_text: String = state.buffer.drain(..end_pos).collect();
|
||||
return Ok(StreamResult::NormalText(malformed_text));
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
|
||||
Reference in New Issue
Block a user