pub enum GenerateEvent<C = GenerationContinuation> {
Started {
model: ModelId,
},
ContentDelta {
delta: String,
},
ThinkingDelta {
delta: String,
},
HostedTool(Box<HostedToolOutput>),
Usage(Usage),
Completed(Box<GenerateResponse<C>>),
}Expand description
Incremental generation event.
Variants§
Started
Stream metadata is ready.
ContentDelta
Incremental visible text.
ThinkingDelta
Incremental provider-authored thinking summary.
HostedTool(Box<HostedToolOutput>)
Incremental provider-hosted tool activity.
Usage(Usage)
Updated provider usage accounting.
Completed(Box<GenerateResponse<C>>)
Terminal normalized response.
Implementations§
Source§impl<C> GenerateEvent<C>
impl<C> GenerateEvent<C>
Sourcepub fn try_map_continuation<D>(
self,
map: impl FnMut(C) -> Result<D, KitError>,
) -> Result<GenerateEvent<D>, KitError>
pub fn try_map_continuation<D>( self, map: impl FnMut(C) -> Result<D, KitError>, ) -> Result<GenerateEvent<D>, KitError>
Maps continuation state carried by a completion event.
§Errors
Returns the callback error for a completion continuation. Other events retain their data without invoking the callback.
§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(),
};
use providers_kit::generation::GenerateEvent;
let event = GenerateEvent::Completed(Box::new(response));
let mapped = event.try_map_continuation(|value| Ok(value.to_string()))?;
assert!(
matches!(mapped, GenerateEvent::Completed(response) if response.message.continuation().map(String::as_str) == Some("7"))
);
Trait Implementations§
Source§impl<C: Clone> Clone for GenerateEvent<C>
impl<C: Clone> Clone for GenerateEvent<C>
Source§impl<C: Debug> Debug for GenerateEvent<C>
impl<C: Debug> Debug for GenerateEvent<C>
Source§impl<'de, C> Deserialize<'de> for GenerateEvent<C>
impl<'de, C> Deserialize<'de> for GenerateEvent<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 GenerateEvent<C>
impl<C: PartialEq> PartialEq for GenerateEvent<C>
Source§impl<C> Serialize for GenerateEvent<C>
impl<C> Serialize for GenerateEvent<C>
impl<C: PartialEq> StructuralPartialEq for GenerateEvent<C>
Auto Trait Implementations§
impl<C> Freeze for GenerateEvent<C>
impl<C> RefUnwindSafe for GenerateEvent<C>
impl<C> Send for GenerateEvent<C>
impl<C> Sync for GenerateEvent<C>
impl<C> Unpin for GenerateEvent<C>
impl<C> UnsafeUnpin for GenerateEvent<C>
impl<C> UnwindSafe for GenerateEvent<C>
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