pub struct ToolWrapper<T: Tool + 'static>(/* private fields */);Expand description
Implementations§
Source§impl<T: Tool + 'static> ToolWrapper<T>
impl<T: Tool + 'static> ToolWrapper<T>
Sourcepub fn new(tool: T) -> Self
pub fn new(tool: T) -> Self
Creates a new ToolWrapper with the given struct that implements the Tool trait.
example:
ⓘ
use rpc_agent::tools::ToolWrapper;
use rig::tool::Tool;
struct MyTool;
impl Tool for MyTool {
const NAME: &'static str = "my_tool";
type Error = anyhow::Error;
type Args = Input;
type Output = u32;
async fn definition(&self, _prompt: String) -> rig::completion::ToolDefinition {
ToolDefinition {
name: "get_ticket_price".to_string(),
description: "Get the price of a return ticket to the destination city.".to_string(),
parameters: serde_json::json!({
"type": "object",
"properties": {
"destination_city": {
"type": "string",
"description": "The destination city"
}
},
"required": ["destination_city"],
}),
}
}
async fn call(&self, _args: Self::Args) -> Result<Self::Output, Self::Error> {
println!("Tools called for {}", &args.destination_city);
let result = Self::get_ticket_price(&args.destination_city)?;
Ok(result)
}
}
let tool = ToolWrapper::new(MyTool);Trait Implementations§
Source§impl<T: Clone + Tool + 'static> Clone for ToolWrapper<T>
impl<T: Clone + Tool + 'static> Clone for ToolWrapper<T>
Source§fn clone(&self) -> ToolWrapper<T>
fn clone(&self) -> ToolWrapper<T>
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreAuto Trait Implementations§
impl<T> Freeze for ToolWrapper<T>
impl<T> RefUnwindSafe for ToolWrapper<T>where
T: RefUnwindSafe,
impl<T> Send for ToolWrapper<T>
impl<T> Sync for ToolWrapper<T>
impl<T> Unpin for ToolWrapper<T>
impl<T> UnsafeUnpin for ToolWrapper<T>
impl<T> UnwindSafe for ToolWrapper<T>where
T: UnwindSafe,
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