Skip to main content

Tool

Struct Tool 

Source
pub struct Tool { /* private fields */ }
Expand description

One tool exposed to the system language model.

Implementations§

Source§

impl Tool

Source

pub fn new<F>( name: impl Into<String>, description: impl Into<String>, parameters: GenerationSchema, handler: F, ) -> Self
where F: Fn(GeneratedContent) -> Result<ToolOutput, FMError> + Send + Sync + 'static,

Create a tool from a dynamic GeneratedContent handler.

Source

pub fn json<Args, Output, F>( name: impl Into<String>, description: impl Into<String>, parameters: GenerationSchema, handler: F, ) -> Self
where Args: DeserializeOwned + Send + 'static, Output: ToPrompt, F: Fn(Args) -> Result<Output, FMError> + Send + Sync + 'static,

Create a tool whose handler receives decoded JSON arguments.

Source

pub fn generable<Args, Output, F>( name: impl Into<String>, description: impl Into<String>, handler: F, ) -> Result<Self, FMError>
where Args: FromGeneratedContent + Generable + Send + 'static, Output: ToPrompt, F: Fn(Args) -> Result<Output, FMError> + Send + Sync + 'static,

Create a tool whose argument schema is inferred from a Generable type.

§Errors

Returns an FMError if Args cannot produce a generation schema.

Source

pub const fn spec(&self) -> &ToolSpec

Tool metadata as exposed to FoundationModels.

Source

pub fn definition(&self) -> ToolDefinition

Convert this tool into a transcript tool definition.

Source

pub fn with_schema_in_instructions(self, includes: bool) -> Self

Control whether the schema is included in the model’s tool instructions.

Trait Implementations§

Source§

impl Debug for Tool

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl !RefUnwindSafe for Tool

§

impl !UnwindSafe for Tool

§

impl Freeze for Tool

§

impl Send for Tool

§

impl Sync for Tool

§

impl Unpin for Tool

§

impl UnsafeUnpin for Tool

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.