pub enum ToolResultContent {
Text(Text),
Image(Image),
Json {
value: Value,
},
}Expand description
Describes one typed item in a tool result.
Variants§
Text(Text)
Literal text. Providers must not reinterpret it as structured JSON.
Image(Image)
An image supplied explicitly by the tool.
Json
Structured JSON supplied explicitly by the tool runtime.
Implementations§
Source§impl ToolResultContent
impl ToolResultContent
Sourcepub fn to_text(&self, image: &str) -> String
pub fn to_text(&self, image: &str) -> String
The content as text: literal text, JSON as its compact text, and an
image as image.
Sourcepub fn deserialize_json<T>(&self) -> Result<T, Error>where
T: DeserializeOwned,
pub fn deserialize_json<T>(&self) -> Result<T, Error>where
T: DeserializeOwned,
Decodes the content as T: structured JSON directly, and text parsed
as JSON, since many tools return JSON as text. An image, or text that
is not T’s JSON, is an error. The content itself is unchanged.
use rig_core::message::ToolResultContent;
let text = ToolResultContent::text(r#"{"count": 3}"#);
let json = ToolResultContent::Json { value: serde_json::json!({"count": 3}) };
for content in [text, json] {
let value: serde_json::Value = content.deserialize_json()?;
assert_eq!(value["count"], 3);
}Source§impl ToolResultContent
impl ToolResultContent
Sourcepub fn text(text: impl Into<String>) -> ToolResultContent
pub fn text(text: impl Into<String>) -> ToolResultContent
Creates literal text tool-result content.
Sourcepub fn json(value: Value) -> ToolResultContent
pub fn json(value: Value) -> ToolResultContent
Creates structured JSON tool-result content.
Sourcepub fn image_base64(
data: impl Into<String>,
media_type: Option<ImageMediaType>,
detail: Option<ImageDetail>,
) -> ToolResultContent
pub fn image_base64( data: impl Into<String>, media_type: Option<ImageMediaType>, detail: Option<ImageDetail>, ) -> ToolResultContent
Creates tool-result image content from base64-encoded data.
Sourcepub fn image_raw(
data: impl Into<Vec<u8>>,
media_type: Option<ImageMediaType>,
detail: Option<ImageDetail>,
) -> ToolResultContent
pub fn image_raw( data: impl Into<Vec<u8>>, media_type: Option<ImageMediaType>, detail: Option<ImageDetail>, ) -> ToolResultContent
Creates tool-result image content from raw, unencoded bytes.
Sourcepub fn image_url(
data: impl Into<String>,
media_type: Option<ImageMediaType>,
detail: Option<ImageDetail>,
) -> ToolResultContent
pub fn image_url( data: impl Into<String>, media_type: Option<ImageMediaType>, detail: Option<ImageDetail>, ) -> ToolResultContent
Creates tool-result image content referencing a URL.
Trait Implementations§
Source§impl Clone for ToolResultContent
impl Clone for ToolResultContent
Source§fn clone(&self) -> ToolResultContent
fn clone(&self) -> ToolResultContent
Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Debug for ToolResultContent
impl Debug for ToolResultContent
Source§impl<'de> Deserialize<'de> for ToolResultContent
impl<'de> Deserialize<'de> for ToolResultContent
Source§fn deserialize<__D>(
__deserializer: __D,
) -> Result<ToolResultContent, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(
__deserializer: __D,
) -> Result<ToolResultContent, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
Source§impl From<String> for ToolResultContent
impl From<String> for ToolResultContent
Source§fn from(text: String) -> ToolResultContent
fn from(text: String) -> ToolResultContent
Converts to this type from the input type.
Source§impl From<ToolResultContent> for ToolOutput
impl From<ToolResultContent> for ToolOutput
Source§fn from(content: ToolResultContent) -> ToolOutput
fn from(content: ToolResultContent) -> ToolOutput
Converts to this type from the input type.
Source§impl PartialEq for ToolResultContent
impl PartialEq for ToolResultContent
Source§impl Serialize for ToolResultContent
impl Serialize for ToolResultContent
Source§fn serialize<__S>(
&self,
__serializer: __S,
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>where
__S: Serializer,
fn serialize<__S>(
&self,
__serializer: __S,
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>where
__S: Serializer,
Serialize this value into the given Serde serializer. Read more
impl StructuralPartialEq for ToolResultContent
Auto Trait Implementations§
impl Forget for ToolResultContent
impl Freeze for ToolResultContent
impl Move for ToolResultContent
impl RefUnwindSafe for ToolResultContent
impl Send for ToolResultContent
impl Sync for ToolResultContent
impl Unpin for ToolResultContent
impl UnsafeUnpin for ToolResultContent
impl UnwindSafe for ToolResultContent
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
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> 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> IntoToolOutput for Twhere
T: Serialize + 'static,
impl<T> IntoToolOutput for Twhere
T: Serialize + 'static,
Source§fn into_tool_output(self) -> Result<ToolOutput, ToolExecutionError>
fn into_tool_output(self) -> Result<ToolOutput, ToolExecutionError>
Convert this value without routing structured data through a string.