pub struct ToolFunction {
pub name: ToolName,
pub arguments: Map<String, Value>,
pub invalid_arguments: Option<String>,
}Expand description
A tool function to call: its name and its arguments, always a JSON object.
Arguments the model sent that are not an object are kept as text in
invalid_arguments, with arguments holding what could be read of them
({} when nothing could), so a malformed call never fails a reply and
every wire receives an object.
use rig_core::message::{ToolFunction, ToolName};
let name = ToolName::new("search")?;
let call = ToolFunction::parse(name.clone(), r#"{"q": "ab"#);
assert_eq!(call.arguments["q"], "ab");
assert_eq!(call.invalid_arguments.as_deref(), Some(r#"{"q": "ab"#));
let call = ToolFunction::new(name, serde_json::json!("{\"q\":1}"));
assert_eq!(call.arguments["q"], 1);
assert!(call.invalid_arguments.is_none());Fields§
§name: ToolNameTool/function name to invoke.
arguments: Map<String, Value>The arguments.
invalid_arguments: Option<String>The arguments as the model sent them, when they were not a JSON object.
Implementations§
Source§impl ToolFunction
impl ToolFunction
Sourcepub fn new(name: ToolName, arguments: Value) -> Self
pub fn new(name: ToolName, arguments: Value) -> Self
A call to name with arguments. An object is kept; a string
holding an object is unwrapped once; null is {}; anything else is
{} with its JSON text in invalid_arguments.
Sourcepub fn parse(name: ToolName, text: &str) -> Self
pub fn parse(name: ToolName, text: &str) -> Self
A call to name with the argument JSON text. Blank text is {}.
Text that is not an object keeps what a cut-off object still states,
or {}, and is kept in invalid_arguments. A string holding an
object is unwrapped once.
Sourcepub fn arguments_value(&self) -> Value
pub fn arguments_value(&self) -> Value
The arguments as a JSON value.
Trait Implementations§
Source§impl Clone for ToolFunction
impl Clone for ToolFunction
Source§impl Debug for ToolFunction
impl Debug for ToolFunction
Source§impl<'de> Deserialize<'de> for ToolFunction
impl<'de> Deserialize<'de> for ToolFunction
Source§fn deserialize<D: Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error>
fn deserialize<D: Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error>
Arguments stored in any JSON shape are read through
ToolFunction::new, so a history saved before arguments were
always objects still loads.
Source§impl PartialEq for ToolFunction
impl PartialEq for ToolFunction
Source§impl Serialize for ToolFunction
impl Serialize for ToolFunction
impl StructuralPartialEq for ToolFunction
Auto Trait Implementations§
impl Freeze for ToolFunction
impl RefUnwindSafe for ToolFunction
impl Send for ToolFunction
impl Sync for ToolFunction
impl Unpin for ToolFunction
impl UnsafeUnpin for ToolFunction
impl UnwindSafe for ToolFunction
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
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> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more