[router][grpc] Consolidate parser checks for chat completions (#11439)

This commit is contained in:
Chang Su
2025-10-10 17:44:29 -07:00
committed by GitHub
parent c495833186
commit 92777135a0
7 changed files with 152 additions and 43 deletions

View File

@@ -11,6 +11,7 @@ pub mod json_parser;
pub mod kimik2_parser;
pub mod llama_parser;
pub mod mistral_parser;
pub mod passthrough_parser;
pub mod pythonic_parser;
pub mod qwen_parser;
pub mod step3_parser;
@@ -27,6 +28,7 @@ pub use json_parser::JsonParser;
pub use kimik2_parser::KimiK2Parser;
pub use llama_parser::LlamaParser;
pub use mistral_parser::MistralParser;
pub use passthrough_parser::PassthroughParser;
pub use pythonic_parser::PythonicParser;
pub use qwen_parser::QwenParser;
pub use step3_parser::Step3Parser;

View File

@@ -0,0 +1,50 @@
//! Passthrough parser that returns text unchanged
//!
//! This parser is used as a fallback for unknown models where no specific
//! tool call parsing should be performed. It simply returns the input text
//! with no tool calls detected.
use crate::protocols::spec::Tool;
use crate::tool_parser::errors::ParserResult;
use crate::tool_parser::traits::ToolParser;
use crate::tool_parser::types::{StreamingParseResult, ToolCall, ToolCallItem};
use async_trait::async_trait;
/// Passthrough parser that returns text unchanged with no tool calls
#[derive(Default)]
pub struct PassthroughParser;
impl PassthroughParser {
pub fn new() -> Self {
Self
}
}
#[async_trait]
impl ToolParser for PassthroughParser {
async fn parse_complete(&self, output: &str) -> ParserResult<(String, Vec<ToolCall>)> {
// Return text unchanged with no tool calls
Ok((output.to_string(), vec![]))
}
async fn parse_incremental(
&mut self,
chunk: &str,
_tools: &[Tool],
) -> ParserResult<StreamingParseResult> {
// Return chunk unchanged with no tool calls
Ok(StreamingParseResult {
normal_text: chunk.to_string(),
calls: vec![],
})
}
fn has_tool_markers(&self, _text: &str) -> bool {
// Passthrough never detects tool calls
false
}
fn get_unstreamed_tool_args(&self) -> Option<Vec<ToolCallItem>> {
None
}
}