pub struct GenerateResponse<C = GenerationContinuation> {
pub model: ModelId,
pub message: Message<C>,
pub finish_reason: Option<FinishReason>,
pub citations: Vec<Citation>,
pub artifacts: Vec<Artifact>,
pub hosted_tool_outputs: Vec<HostedToolOutput>,
pub usage: Usage,
}Expand description
Final normalized generation result.
A returned assistant message is the replay owner. Preserve it unchanged through function continuation; projections of text, hosted results, or artifacts cannot reconstruct native state. Serialization fails while continuation is present.
§Examples
use providers_kit::{ModelId, generation::{GenerateResponse, Message, FinishReason, Usage}};
let response = GenerateResponse { model: ModelId::new("exact-model")?, message: Message::assistant_text("done")?.with_continuation(7_u32)?, finish_reason: Some(FinishReason::Stop), citations: Vec::new(), artifacts: Vec::new(), hosted_tool_outputs: Vec::new(), usage: Usage::default() };
let mapped = response.try_map_continuation(|value| Ok(value.to_string()))?;
assert_eq!(mapped.message.continuation().map(String::as_str), Some("7"));
assert_eq!(mapped.model.as_str(), "exact-model");
Fields§
§model: ModelIdExact model that produced the response.
message: Message<C>Returned assistant message and opaque continuation state.
finish_reason: Option<FinishReason>Provider-reported completion reason.
citations: Vec<Citation>Citations attached to generated output.
artifacts: Vec<Artifact>Generated artifacts.
hosted_tool_outputs: Vec<HostedToolOutput>Normalized provider-hosted tool outputs.
usage: UsageProvider-reported token accounting.
Implementations§
Source§impl<C> GenerateResponse<C>
impl<C> GenerateResponse<C>
Sourcepub fn try_map_continuation<D>(
self,
map: impl FnMut(C) -> Result<D, KitError>,
) -> Result<GenerateResponse<D>, KitError>
pub fn try_map_continuation<D>( self, map: impl FnMut(C) -> Result<D, KitError>, ) -> Result<GenerateResponse<D>, KitError>
Maps only opaque continuation values.
§Errors
Returns the callback error unchanged if converting the response continuation fails; other response fields retain their exact values.
§Examples
use providers_kit::{ModelId, generation::{GenerateResponse, Message, FinishReason, Usage}};
let response = GenerateResponse { model: ModelId::new("exact-model")?, message: Message::assistant_text("done")?.with_continuation(7_u32)?, finish_reason: Some(FinishReason::Stop), citations: Vec::new(), artifacts: Vec::new(), hosted_tool_outputs: Vec::new(), usage: Usage::default() };
let mapped = response.try_map_continuation(|value| Ok(value.to_string()))?;
assert_eq!(mapped.message.continuation().map(String::as_str), Some("7"));
assert_eq!(mapped.model.as_str(), "exact-model");
Trait Implementations§
Source§impl<C: Clone> Clone for GenerateResponse<C>
impl<C: Clone> Clone for GenerateResponse<C>
Source§impl<C: Debug> Debug for GenerateResponse<C>
impl<C: Debug> Debug for GenerateResponse<C>
Source§impl<'de, C> Deserialize<'de> for GenerateResponse<C>
impl<'de, C> Deserialize<'de> for GenerateResponse<C>
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<C: PartialEq> PartialEq for GenerateResponse<C>
impl<C: PartialEq> PartialEq for GenerateResponse<C>
Source§impl<C> Serialize for GenerateResponse<C>
impl<C> Serialize for GenerateResponse<C>
impl<C: PartialEq> StructuralPartialEq for GenerateResponse<C>
Auto Trait Implementations§
impl<C> Freeze for GenerateResponse<C>
impl<C> RefUnwindSafe for GenerateResponse<C>where
Message<C>: RefUnwindSafe,
impl<C> Send for GenerateResponse<C>
impl<C> Sync for GenerateResponse<C>
impl<C> Unpin for GenerateResponse<C>
impl<C> UnsafeUnpin for GenerateResponse<C>where
Message<C>: UnsafeUnpin,
impl<C> UnwindSafe for GenerateResponse<C>where
Message<C>: UnwindSafe,
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