/*
* 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};
/// RealtimeSession : Realtime session object for the beta interface.
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize, bon::Builder)]
pub struct RealtimeSession {
/// Unique identifier for the session that looks like `sess_1234567890abcdef`.
#[serde(rename = "id", skip_serializing_if = "Option::is_none")]
pub id: Option<String>,
/// The object type. Always `realtime.session`.
#[serde(rename = "object", skip_serializing_if = "Option::is_none")]
pub object: Option<Object>,
#[serde(
rename = "modalities",
default,
with = "::serde_with::rust::double_option",
skip_serializing_if = "Option::is_none"
)]
pub modalities: Option<Option<serde_json::Value>>,
/// The Realtime model used for this session.
#[serde(rename = "model", skip_serializing_if = "Option::is_none")]
pub model: Option<String>,
/// The default system instructions (i.e. system message) prepended to model calls. This field allows the client to guide the model on desired responses. The model can be instructed on response content and format, (e.g. \"be extremely succinct\", \"act friendly\", \"here are examples of good responses\") and on audio behavior (e.g. \"talk quickly\", \"inject emotion into your voice\", \"laugh frequently\"). The instructions are not guaranteed to be followed by the model, but they provide guidance to the model on the desired behavior. Note that the server sets default instructions which will be used if this field is not set and are visible in the `session.created` event at the start of the session.
#[serde(rename = "instructions", skip_serializing_if = "Option::is_none")]
pub instructions: Option<String>,
/// The voice the model uses to respond. Voice cannot be changed during the session once the model has responded with audio at least once. Current voice options are `alloy`, `ash`, `ballad`, `coral`, `echo`, `sage`, `shimmer`, and `verse`.
#[serde(rename = "voice", skip_serializing_if = "Option::is_none")]
pub voice: Option<String>,
/// The format of input audio. Options are `pcm16`, `g711_ulaw`, or `g711_alaw`. For `pcm16`, input audio must be 16-bit PCM at a 24kHz sample rate, single channel (mono), and little-endian byte order.
#[serde(rename = "input_audio_format", skip_serializing_if = "Option::is_none")]
pub input_audio_format: Option<InputAudioFormat>,
/// The format of output audio. Options are `pcm16`, `g711_ulaw`, or `g711_alaw`. For `pcm16`, output audio is sampled at a rate of 24kHz.
#[serde(
rename = "output_audio_format",
skip_serializing_if = "Option::is_none"
)]
pub output_audio_format: Option<OutputAudioFormat>,
/// Configuration for input audio transcription, defaults to off and can be set to `null` to turn off once on. Input audio transcription is not native to the model, since the model consumes audio directly. Transcription runs asynchronously through [the /audio/transcriptions endpoint](https://platform.openai.com/docs/api-reference/audio/createTranscription) and should be treated as guidance of input audio content rather than precisely what the model heard. The client can optionally set the language and prompt for transcription, these offer additional guidance to the transcription service.
#[serde(
rename = "input_audio_transcription",
default,
with = "::serde_with::rust::double_option",
skip_serializing_if = "Option::is_none"
)]
pub input_audio_transcription: Option<Option<Box<models::AudioTranscription>>>,
#[serde(
rename = "turn_detection",
default,
with = "::serde_with::rust::double_option",
skip_serializing_if = "Option::is_none"
)]
pub turn_detection: Option<Option<Box<models::RealtimeTurnDetection>>>,
#[serde(
rename = "input_audio_noise_reduction",
skip_serializing_if = "Option::is_none"
)]
pub input_audio_noise_reduction: Option<Box<models::RealtimeSessionInputAudioNoiseReduction>>,
/// The speed of the model's spoken response. 1.0 is the default speed. 0.25 is the minimum speed. 1.5 is the maximum speed. This value can only be changed in between model turns, not while a response is in progress.
#[serde(rename = "speed", skip_serializing_if = "Option::is_none")]
pub speed: Option<f64>,
#[serde(
rename = "tracing",
default,
with = "::serde_with::rust::double_option",
skip_serializing_if = "Option::is_none"
)]
pub tracing: Option<Option<Box<models::TracingConfiguration>>>,
/// Tools (functions) available to the model.
#[serde(rename = "tools", skip_serializing_if = "Option::is_none")]
pub tools: Option<Vec<models::RealtimeFunctionTool>>,
/// How the model chooses tools. Options are `auto`, `none`, `required`, or specify a function.
#[serde(rename = "tool_choice", skip_serializing_if = "Option::is_none")]
pub tool_choice: Option<String>,
/// Sampling temperature for the model, limited to [0.6, 1.2]. For audio models a temperature of 0.8 is highly recommended for best performance.
#[serde(rename = "temperature", skip_serializing_if = "Option::is_none")]
pub temperature: Option<f64>,
#[serde(
rename = "max_response_output_tokens",
skip_serializing_if = "Option::is_none"
)]
pub max_response_output_tokens:
Option<Box<models::RealtimeBetaResponseCreateParamsMaxOutputTokens>>,
/// Expiration timestamp for the session, in seconds since epoch.
#[serde(rename = "expires_at", skip_serializing_if = "Option::is_none")]
pub expires_at: Option<i32>,
#[serde(
rename = "prompt",
default,
with = "::serde_with::rust::double_option",
skip_serializing_if = "Option::is_none"
)]
pub prompt: Option<Option<Box<models::Prompt>>>,
/// Additional fields to include in server outputs. - `item.input_audio_transcription.logprobs`: Include logprobs for input audio transcription.
#[serde(
rename = "include",
default,
with = "::serde_with::rust::double_option",
skip_serializing_if = "Option::is_none"
)]
pub include: Option<Option<Vec<Include>>>,
}
impl RealtimeSession {
/// Realtime session object for the beta interface.
pub fn new() -> RealtimeSession {
RealtimeSession {
id: None,
object: None,
modalities: None,
model: None,
instructions: None,
voice: None,
input_audio_format: None,
output_audio_format: None,
input_audio_transcription: None,
turn_detection: None,
input_audio_noise_reduction: None,
speed: None,
tracing: None,
tools: None,
tool_choice: None,
temperature: None,
max_response_output_tokens: None,
expires_at: None,
prompt: None,
include: None,
}
}
}
/// The object type. Always `realtime.session`.
#[derive(Clone, Copy, Debug, Eq, PartialEq, Ord, PartialOrd, Hash, Serialize, Deserialize)]
pub enum Object {
#[serde(rename = "realtime.session")]
RealtimeSession,
}
impl Default for Object {
fn default() -> Object {
Self::RealtimeSession
}
}
/// The format of input audio. Options are `pcm16`, `g711_ulaw`, or `g711_alaw`. For `pcm16`, input audio must be 16-bit PCM at a 24kHz sample rate, single channel (mono), and little-endian byte order.
#[derive(Clone, Copy, Debug, Eq, PartialEq, Ord, PartialOrd, Hash, Serialize, Deserialize)]
pub enum InputAudioFormat {
#[serde(rename = "pcm16")]
Pcm16,
#[serde(rename = "g711_ulaw")]
G711Ulaw,
#[serde(rename = "g711_alaw")]
G711Alaw,
}
impl Default for InputAudioFormat {
fn default() -> InputAudioFormat {
Self::Pcm16
}
}
/// The format of output audio. Options are `pcm16`, `g711_ulaw`, or `g711_alaw`. For `pcm16`, output audio is sampled at a rate of 24kHz.
#[derive(Clone, Copy, Debug, Eq, PartialEq, Ord, PartialOrd, Hash, Serialize, Deserialize)]
pub enum OutputAudioFormat {
#[serde(rename = "pcm16")]
Pcm16,
#[serde(rename = "g711_ulaw")]
G711Ulaw,
#[serde(rename = "g711_alaw")]
G711Alaw,
}
impl Default for OutputAudioFormat {
fn default() -> OutputAudioFormat {
Self::Pcm16
}
}
/// Additional fields to include in server outputs. - `item.input_audio_transcription.logprobs`: Include logprobs for input audio transcription.
#[derive(Clone, Copy, Debug, Eq, PartialEq, Ord, PartialOrd, Hash, Serialize, Deserialize)]
pub enum Include {
#[serde(rename = "item.input_audio_transcription.logprobs")]
ItemInputAudioTranscriptionLogprobs,
}
impl Default for Include {
fn default() -> Include {
Self::ItemInputAudioTranscriptionLogprobs
}
}
impl std::fmt::Display for RealtimeSession {
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),
}
}
}