/*
* OpenAI API
*
* The OpenAI REST API. Please see https://platform.openai.com/docs/api-reference for more details.
*
* The version of the OpenAPI document: 2.3.0
*
* Generated by: https://openapi-generator.tech
*/
use crate::models;
use serde::{Deserialize, Serialize};
/// RealtimeClientEventConversationItemTruncate : Send this event to truncate a previous assistant message’s audio. The server will produce audio faster than realtime, so this event is useful when the user interrupts to truncate audio that has already been sent to the client but not yet played. This will synchronize the server's understanding of the audio with the client's playback. Truncating audio will delete the server-side text transcript to ensure there is not text in the context that hasn't been heard by the user. If successful, the server will respond with a `conversation.item.truncated` event.
#[derive(Clone, Default, Debug, PartialEq, Serialize, Deserialize, bon::Builder)]
pub struct RealtimeClientEventConversationItemTruncate {
/// Optional client-generated ID used to identify this event.
#[serde(rename = "event_id", skip_serializing_if = "Option::is_none")]
pub event_id: Option<String>,
/// The event type, must be `conversation.item.truncate`.
#[serde(rename = "type")]
pub r#type: Type,
/// The ID of the assistant message item to truncate. Only assistant message items can be truncated.
#[serde(rename = "item_id")]
pub item_id: String,
/// The index of the content part to truncate. Set this to `0`.
#[serde(rename = "content_index")]
pub content_index: i32,
/// Inclusive duration up to which audio is truncated, in milliseconds. If the audio_end_ms is greater than the actual audio duration, the server will respond with an error.
#[serde(rename = "audio_end_ms")]
pub audio_end_ms: i32,
}
impl RealtimeClientEventConversationItemTruncate {
/// Send this event to truncate a previous assistant message’s audio. The server will produce audio faster than realtime, so this event is useful when the user interrupts to truncate audio that has already been sent to the client but not yet played. This will synchronize the server's understanding of the audio with the client's playback. Truncating audio will delete the server-side text transcript to ensure there is not text in the context that hasn't been heard by the user. If successful, the server will respond with a `conversation.item.truncated` event.
pub fn new(
r#type: Type,
item_id: String,
content_index: i32,
audio_end_ms: i32,
) -> RealtimeClientEventConversationItemTruncate {
RealtimeClientEventConversationItemTruncate {
event_id: None,
r#type,
item_id,
content_index,
audio_end_ms,
}
}
}
/// The event type, must be `conversation.item.truncate`.
#[derive(Clone, Copy, Debug, Eq, PartialEq, Ord, PartialOrd, Hash, Serialize, Deserialize)]
pub enum Type {
#[serde(rename = "conversation.item.truncate")]
ConversationItemTruncate,
}
impl Default for Type {
fn default() -> Type {
Self::ConversationItemTruncate
}
}
impl std::fmt::Display for RealtimeClientEventConversationItemTruncate {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match serde_json::to_string(self) {
Ok(s) => write!(f, "{}", s),
Err(_) => Err(std::fmt::Error),
}
}
}