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) -> ToolFunction
pub fn new(name: ToolName, arguments: Value) -> ToolFunction
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) -> ToolFunction
pub fn parse(name: ToolName, text: &str) -> ToolFunction
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.
Sourcepub fn arguments_json(&self) -> String
pub fn arguments_json(&self) -> String
The arguments object as JSON text, as Self::arguments_value
prints, without copying it.
Sourcepub fn raw_arguments(&self) -> String
pub fn raw_arguments(&self) -> String
The arguments as JSON text: what the model sent when it was not an object, else the object.
Trait Implementations§
Source§impl Clone for ToolFunction
impl Clone for ToolFunction
Source§fn clone(&self) -> ToolFunction
fn clone(&self) -> ToolFunction
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§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: D,
) -> Result<ToolFunction, <D as Deserializer<'de>>::Error>where
D: Deserializer<'de>,
fn deserialize<D>(
deserializer: D,
) -> Result<ToolFunction, <D as Deserializer<'de>>::Error>where
D: Deserializer<'de>,
Arguments stored in any JSON shape are read through
ToolFunction::new, so a history saved before arguments were
always objects still loads.