pub struct ToolRegistry { /* private fields */ }Expand description
Registry that maps tool names to their JSON Schema definitions and async handler functions.
Pass the definitions to [ChatRequest::tools] when calling Ollama and call
ToolRegistry::dispatch when the model returns a tool-call in its reply.
Implementations§
Source§impl ToolRegistry
impl ToolRegistry
pub fn new() -> Self
Sourcepub fn register<F, Fut>(&mut self, definition: ToolDefinition, handler: F)
pub fn register<F, Fut>(&mut self, definition: ToolDefinition, handler: F)
Register a tool with its JSON Schema definition and an async handler.
The handler receives the arguments object from Ollama’s tool-call
response and must return a JSON value that will be fed back as the
tool result.
Sourcepub fn definitions(&self) -> Vec<ToolDefinition>
pub fn definitions(&self) -> Vec<ToolDefinition>
All definitions, ready to pass directly to [ChatRequest::tools].
Sourcepub async fn dispatch(
&self,
tool_name: &str,
args: Value,
) -> Result<Value, OxideError>
pub async fn dispatch( &self, tool_name: &str, args: Value, ) -> Result<Value, OxideError>
Execute the handler for tool_name with the given arguments.
Returns Err(OxideError::Other) if the tool name is not registered.
pub fn contains(&self, name: &str) -> bool
pub fn len(&self) -> usize
pub fn is_empty(&self) -> bool
Trait Implementations§
Source§impl Default for ToolRegistry
impl Default for ToolRegistry
Source§fn default() -> ToolRegistry
fn default() -> ToolRegistry
Returns the “default value” for a type. Read more
Auto Trait Implementations§
impl Freeze for ToolRegistry
impl !RefUnwindSafe for ToolRegistry
impl Send for ToolRegistry
impl Sync for ToolRegistry
impl Unpin for ToolRegistry
impl UnsafeUnpin for ToolRegistry
impl !UnwindSafe for ToolRegistry
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