pub struct JsonParser { /* private fields */ }Expand description
JSON format parser for tool calls
Handles pure JSON formats for function calling:
- Single tool call: {“name”: “fn”, “arguments”: {…}}
- Multiple tool calls: [{“name”: “fn1”, “arguments”: {…}}, …]
- With parameters instead of arguments: {“name”: “fn”, “parameters”: {…}}
Implementations§
Source§impl JsonParser
impl JsonParser
Trait Implementations§
Source§impl Default for JsonParser
impl Default for JsonParser
Source§impl ToolParser for JsonParser
impl ToolParser for JsonParser
Source§fn parse_complete<'life0, 'life1, 'async_trait>(
&'life0 self,
text: &'life1 str,
) -> Pin<Box<dyn Future<Output = ParserResult<(String, Vec<ToolCall>)>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn parse_complete<'life0, 'life1, 'async_trait>(
&'life0 self,
text: &'life1 str,
) -> Pin<Box<dyn Future<Output = ParserResult<(String, Vec<ToolCall>)>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
Parse complete tool calls from final output
Returns (remaining_normal_text, tool_calls) tuple
Source§fn parse_incremental<'life0, 'life1, 'life2, 'async_trait>(
&'life0 mut self,
chunk: &'life1 str,
tools: &'life2 [Tool],
) -> Pin<Box<dyn Future<Output = ParserResult<StreamingParseResult>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
fn parse_incremental<'life0, 'life1, 'life2, 'async_trait>(
&'life0 mut self,
chunk: &'life1 str,
tools: &'life2 [Tool],
) -> Pin<Box<dyn Future<Output = ParserResult<StreamingParseResult>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
Parse tool calls from model output (streaming)
Parsers now maintain internal state, so self is mutable Read more
Source§fn has_tool_markers(&self, text: &str) -> bool
fn has_tool_markers(&self, text: &str) -> bool
Check if text contains tool calls in this parser’s format
Source§fn get_unstreamed_tool_args(&self) -> Option<Vec<ToolCallItem>>
fn get_unstreamed_tool_args(&self) -> Option<Vec<ToolCallItem>>
Get unstreamed tool call arguments
Returns tool call items for arguments that have been parsed but not yet streamed
Source§fn reset(&mut self)
fn reset(&mut self)
Reset the parser state for reuse across requests.
This should clear all buffers and reset state to initial values.
Source§fn as_token_parser(&self) -> Option<&dyn TokenToolParser>
fn as_token_parser(&self) -> Option<&dyn TokenToolParser>
Optionally expose a token-aware parser implementation.
Default returns
None, meaning the parser only supports text input.Auto Trait Implementations§
impl Freeze for JsonParser
impl RefUnwindSafe for JsonParser
impl Send for JsonParser
impl Sync for JsonParser
impl Unpin for JsonParser
impl UnwindSafe for JsonParser
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more