pub struct ToolDefinition {
pub name: ToolName,
pub description: ToolDescription,
pub parameters: GenerationSchema,
/* private fields */
}Expand description
A function that the model can invoke when responding to a prompt.
The handler receives the model’s arguments as a serde_json::Value and must return
either a ToolOutput delivered back to the model or a ToolCallError.
Build one with ToolDefinition::builder, then attach it to a LanguageModelSessionBuilder.
Fields§
§name: ToolNameName the model uses to reference this tool. Must be unique within a session.
description: ToolDescriptionHuman-readable description shown to the model.
parameters: GenerationSchemaGenerationSchema describing the arguments the model must supply when calling this tool.
Implementations§
Source§impl ToolDefinition
impl ToolDefinition
Sourcepub fn new(
name: impl Into<ToolName>,
description: impl Into<ToolDescription>,
parameters: GenerationSchema,
handler: impl Fn(Value) -> ToolResult + WasmCompatSend + WasmCompatSync + 'static,
) -> Self
pub fn new( name: impl Into<ToolName>, description: impl Into<ToolDescription>, parameters: GenerationSchema, handler: impl Fn(Value) -> ToolResult + WasmCompatSend + WasmCompatSync + 'static, ) -> Self
Creates a complete tool definition from a typed handler.
Sourcepub fn builder(
name: impl Into<ToolName>,
description: impl Into<ToolDescription>,
parameters: GenerationSchema,
) -> ToolDefinitionBuilder
pub fn builder( name: impl Into<ToolName>, description: impl Into<ToolDescription>, parameters: GenerationSchema, ) -> ToolDefinitionBuilder
Starts building a tool definition.
Sourcepub fn from_handler(
name: impl Into<ToolName>,
description: impl Into<ToolDescription>,
parameters: GenerationSchema,
handler: impl Fn(Value) -> ToolResult + WasmCompatSend + WasmCompatSync + 'static,
) -> Self
pub fn from_handler( name: impl Into<ToolName>, description: impl Into<ToolDescription>, parameters: GenerationSchema, handler: impl Fn(Value) -> ToolResult + WasmCompatSend + WasmCompatSync + 'static, ) -> Self
Alias for ToolDefinition::new that reads well at call sites.
Trait Implementations§
Source§impl Debug for ToolDefinition
impl Debug for ToolDefinition
Source§impl Tool for ToolDefinition
impl Tool for ToolDefinition
Source§fn description(&self) -> &ToolDescription
fn description(&self) -> &ToolDescription
Returns the human-readable tool description visible to the model.
Source§fn parameters(&self) -> &GenerationSchema
fn parameters(&self) -> &GenerationSchema
Returns the JSON argument schema visible to the model.
Auto Trait Implementations§
impl Freeze for ToolDefinition
impl !RefUnwindSafe for ToolDefinition
impl Send for ToolDefinition
impl Sync for ToolDefinition
impl Unpin for ToolDefinition
impl UnsafeUnpin for ToolDefinition
impl !UnwindSafe for ToolDefinition
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