pub struct FunctionResult { /* private fields */ }Expand description
Validated caller-supplied result for a client function call.
§Examples
use providers_kit::generation::{FunctionResult, ContentPart};
let result = FunctionResult::new(Some("call-1".into()), "lookup", vec![ContentPart::Json { value: serde_json::json!({"value":2}) }], false)?;
assert_eq!(result.call_id(), Some("call-1"));
assert_eq!(result.name(), "lookup");
assert_eq!(result.content().len(), 1);
assert!(!result.is_error());
Implementations§
Source§impl FunctionResult
impl FunctionResult
Sourcepub fn new(
call_id: Option<String>,
name: impl Into<String>,
content: Vec<ContentPart>,
is_error: bool,
) -> Result<Self, KitError>
pub fn new( call_id: Option<String>, name: impl Into<String>, content: Vec<ContentPart>, is_error: bool, ) -> Result<Self, KitError>
Creates a validated function result.
§Errors
Returns an input error for an invalid name/id, empty or invalid content, or provider thinking content. Accepted function failures use is_error = true with nonempty model-visible content.
§Examples
use providers_kit::generation::{FunctionResult, ContentPart};
let result = FunctionResult::new(Some("call-1".into()), "lookup", vec![ContentPart::Json { value: serde_json::json!({"value":2}) }], false)?;
assert_eq!(result.call_id(), Some("call-1"));
assert_eq!(result.name(), "lookup");
assert_eq!(result.content().len(), 1);
assert!(!result.is_error());
Sourcepub fn call_id(&self) -> Option<&str>
pub fn call_id(&self) -> Option<&str>
Returns the originating call id, when available.
§Examples
use providers_kit::generation::{FunctionResult, ContentPart};
let result = FunctionResult::new(Some("call-1".into()), "lookup", vec![ContentPart::Json { value: serde_json::json!({"value":2}) }], false)?;
assert_eq!(result.call_id(), Some("call-1"));
assert_eq!(result.name(), "lookup");
assert_eq!(result.content().len(), 1);
assert!(!result.is_error());
Sourcepub fn name(&self) -> &str
pub fn name(&self) -> &str
Returns the function name.
§Examples
use providers_kit::generation::{FunctionResult, ContentPart};
let result = FunctionResult::new(Some("call-1".into()), "lookup", vec![ContentPart::Json { value: serde_json::json!({"value":2}) }], false)?;
assert_eq!(result.call_id(), Some("call-1"));
assert_eq!(result.name(), "lookup");
assert_eq!(result.content().len(), 1);
assert!(!result.is_error());
Sourcepub fn content(&self) -> &[ContentPart]
pub fn content(&self) -> &[ContentPart]
Returns ordered model-visible result content.
§Examples
use providers_kit::generation::{FunctionResult, ContentPart};
let result = FunctionResult::new(Some("call-1".into()), "lookup", vec![ContentPart::Json { value: serde_json::json!({"value":2}) }], false)?;
assert_eq!(result.call_id(), Some("call-1"));
assert_eq!(result.name(), "lookup");
assert_eq!(result.content().len(), 1);
assert!(!result.is_error());
Sourcepub const fn is_error(&self) -> bool
pub const fn is_error(&self) -> bool
Reports whether the completed function execution failed.
§Examples
use providers_kit::generation::{FunctionResult, ContentPart};
let result = FunctionResult::new(Some("call-1".into()), "lookup", vec![ContentPart::Json { value: serde_json::json!({"value":2}) }], false)?;
assert_eq!(result.call_id(), Some("call-1"));
assert_eq!(result.name(), "lookup");
assert_eq!(result.content().len(), 1);
assert!(!result.is_error());
Trait Implementations§
Source§impl Clone for FunctionResult
impl Clone for FunctionResult
Source§impl Debug for FunctionResult
impl Debug for FunctionResult
Source§impl<'de> Deserialize<'de> for FunctionResult
impl<'de> Deserialize<'de> for FunctionResult
Source§fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>where
D: Deserializer<'de>,
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>where
D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
Source§impl PartialEq for FunctionResult
impl PartialEq for FunctionResult
Source§impl Serialize for FunctionResult
impl Serialize for FunctionResult
impl StructuralPartialEq for FunctionResult
Auto Trait Implementations§
impl Freeze for FunctionResult
impl RefUnwindSafe for FunctionResult
impl Send for FunctionResult
impl Sync for FunctionResult
impl Unpin for FunctionResult
impl UnsafeUnpin for FunctionResult
impl UnwindSafe for FunctionResult
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