pub struct ToolCallDetector { /* private fields */ }Expand description
Incremental tool-call detector.
Feed token text via feed as tokens are generated.
When a complete tool call (open delimiter + valid JSON + close delimiter)
is recognised, feed returns Some(ToolCall).
The detector maintains a rolling scan buffer to handle delimiters that span multiple tokens.
§Example
use oxillama_runtime::tool_dispatch::{ToolCallDetector, ToolCallGrammar};
let mut detector = ToolCallDetector::new(ToolCallGrammar::Llama3);
let call = detector.feed("<|tool_call|>{\"name\":\"ping\",\"args\":{}}<|/tool_call|>");
assert!(call.is_some());Implementations§
Source§impl ToolCallDetector
impl ToolCallDetector
Sourcepub fn new(grammar: ToolCallGrammar) -> Self
pub fn new(grammar: ToolCallGrammar) -> Self
Construct a new detector for the given grammar.
Sourcepub fn feed(&mut self, token_text: &str) -> Option<ToolCall>
pub fn feed(&mut self, token_text: &str) -> Option<ToolCall>
Feed one token’s decoded text into the detector.
Returns Some(ToolCall) when a complete, valid tool call is detected.
Returns None while the tool call is still accumulating or if the text
is not a tool call.
After returning Some, the detector automatically resets to Idle.
This means it can detect multiple sequential tool calls: feed text
from the second call and it will be detected in a subsequent call.
Auto Trait Implementations§
impl Freeze for ToolCallDetector
impl RefUnwindSafe for ToolCallDetector
impl Send for ToolCallDetector
impl Sync for ToolCallDetector
impl Unpin for ToolCallDetector
impl UnsafeUnpin for ToolCallDetector
impl UnwindSafe for ToolCallDetector
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