pub struct Tool {
pub name: String,
pub description: String,
pub parameters: Value,
}Expand description
Tool definition with JSON Schema parameters
Fields§
§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: JsonValue,
) -> Self
pub fn new( name: impl Into<String>, description: impl Into<String>, parameters: JsonValue, ) -> Self
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>,
) -> Self
pub fn with_string_param( name: impl Into<String>, description: impl Into<String>, param_name: impl Into<String>, param_description: impl Into<String>, ) -> Self
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: &JsonValue,
) -> Result<JsonValue, ToolValidationError>
pub fn validate( &self, args: &JsonValue, ) -> Result<JsonValue, 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<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. 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