pub struct Tool {
pub name: String,
pub description: String,
pub parameters: Value,
}Expand description
Stable since 0.63.0
Tool definition with JSON Schema parametersFields§
§name: StringTool name
description: StringHuman-readable description
parameters: ValueJSON Schema for parameters
Implementations§
Source§impl Tool
impl Tool
Sourcepub fn new(
name: impl Into<String>,
description: impl Into<String>,
parameters: Value,
) -> Tool
pub fn new( name: impl Into<String>, description: impl Into<String>, parameters: Value, ) -> Tool
Create a new tool with the given name, description, and JSON Schema.
§Examples
use oxicode_ai::Tool;
let tool = Tool::new(
"read_file",
"Read contents from a file",
serde_json::json!({
"type": "object",
"properties": {
"path": {
"type": "string",
"description": "File path to read"
}
},
"required": ["path"]
}),
);Sourcepub fn with_string_param(
name: impl Into<String>,
description: impl Into<String>,
param_name: impl Into<String>,
param_description: impl Into<String>,
) -> Tool
pub fn with_string_param( name: impl Into<String>, description: impl Into<String>, param_name: impl Into<String>, param_description: impl Into<String>, ) -> Tool
Create a simple tool with a single string parameter
§Examples
use oxicode_ai::Tool;
let tool = Tool::with_string_param(
"get_weather",
"Get current weather",
"location",
"City name",
);
assert_eq!(tool.name, "get_weather");Sourcepub fn validate(&self, args: &Value) -> Result<Value, ToolValidationError>
pub fn validate(&self, args: &Value) -> Result<Value, ToolValidationError>
Validate arguments against the tool’s JSON Schema
§Examples
use oxicode_ai::Tool;
let tool = Tool::with_string_param(
"get_weather",
"Get weather",
"location",
"City",
);
let result = tool.validate(&serde_json::json!({"location": "London"}));
assert!(result.is_ok());Sourcepub fn requires_parameters(&self) -> bool
pub fn requires_parameters(&self) -> bool
Check if this tool requires parameters
Trait Implementations§
Source§impl<'de> Deserialize<'de> for Tool
impl<'de> Deserialize<'de> for Tool
Source§fn deserialize<__D>(
__deserializer: __D,
) -> Result<Tool, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(
__deserializer: __D,
) -> Result<Tool, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
Source§impl Serialize for Tool
impl Serialize for Tool
Source§fn serialize<__S>(
&self,
__serializer: __S,
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>where
__S: Serializer,
fn serialize<__S>(
&self,
__serializer: __S,
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>where
__S: Serializer,
Serialize this value into the given Serde serializer. Read more
Auto Trait Implementations§
impl Freeze for Tool
impl RefUnwindSafe for Tool
impl Send for Tool
impl Sync for Tool
impl Unpin for Tool
impl UnsafeUnpin for Tool
impl UnwindSafe for Tool
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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> DeserializeOwned for Twhere
T: for<'de> Deserialize<'de>,
Source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Convert
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can
then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.Source§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Convert
Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be
further downcast into Rc<ConcreteType> where ConcreteType implements Trait.Source§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
Convert
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.Source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
Convert
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.