Skip to main content

tool_parser/parsers/
passthrough.rs

1//! Passthrough parser that returns text unchanged
2//!
3//! This parser is used as a fallback for unknown models where no specific
4//! tool call parsing should be performed. It simply returns the input text
5//! with no tool calls detected.
6
7use async_trait::async_trait;
8use openai_protocol::common::Tool;
9
10use crate::{
11    errors::ParserResult,
12    traits::ToolParser,
13    types::{StreamingParseResult, ToolCall, ToolCallItem},
14};
15
16/// Passthrough parser that returns text unchanged with no tool calls
17#[derive(Default)]
18pub(crate) struct PassthroughParser;
19
20impl PassthroughParser {
21    pub fn new() -> Self {
22        Self
23    }
24}
25
26#[async_trait]
27impl ToolParser for PassthroughParser {
28    async fn parse_complete(&self, output: &str) -> ParserResult<(String, Vec<ToolCall>)> {
29        // Return text unchanged with no tool calls
30        Ok((output.to_string(), vec![]))
31    }
32
33    async fn parse_incremental(
34        &mut self,
35        chunk: &str,
36        _tools: &[Tool],
37    ) -> ParserResult<StreamingParseResult> {
38        // Return chunk unchanged with no tool calls
39        Ok(StreamingParseResult {
40            normal_text: chunk.to_string(),
41            calls: vec![],
42        })
43    }
44
45    fn has_tool_markers(&self, _text: &str) -> bool {
46        // Passthrough never detects tool calls
47        false
48    }
49
50    fn get_unstreamed_tool_args(&self) -> Option<Vec<ToolCallItem>> {
51        None
52    }
53}