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