pub struct RealtimeClient { /* private fields */ }Expand description
Builder for creating Realtime API connections.
§Example
use openai_tools::realtime::{RealtimeClient, Modality, Voice};
use openai_tools::common::models::RealtimeModel;
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let mut client = RealtimeClient::new();
client
.model(RealtimeModel::Gpt4oRealtimePreview)
.modalities(vec![Modality::Text, Modality::Audio])
.voice(Voice::Alloy)
.instructions("You are a helpful assistant.");
let mut session = client.connect().await?;
// Use session...
session.close().await?;
Ok(())
}Implementations§
Source§impl RealtimeClient
impl RealtimeClient
Sourcepub fn new() -> Self
pub fn new() -> Self
Create a new RealtimeClient for OpenAI API.
Loads the API key from the OPENAI_API_KEY environment variable.
Sourcepub fn with_auth(auth: AuthProvider) -> Self
pub fn with_auth(auth: AuthProvider) -> Self
Create a new RealtimeClient with a custom authentication provider.
Sourcepub fn detect_provider() -> Result<Self>
pub fn detect_provider() -> Result<Self>
Create a new RealtimeClient by auto-detecting the provider.
Sourcepub fn with_url<S: Into<String>>(base_url: S, api_key: S) -> Self
pub fn with_url<S: Into<String>>(base_url: S, api_key: S) -> Self
Creates a new RealtimeClient with URL-based provider detection.
Sourcepub fn from_url<S: Into<String>>(url: S) -> Result<Self>
pub fn from_url<S: Into<String>>(url: S) -> Result<Self>
Creates a new RealtimeClient from URL using environment variables.
Sourcepub fn with_api_key(api_key: impl Into<String>) -> Self
👎Deprecated since 0.3.0: Use with_auth(AuthProvider::OpenAI(...)) instead
pub fn with_api_key(api_key: impl Into<String>) -> Self
with_auth(AuthProvider::OpenAI(...)) insteadCreate a new RealtimeClient with an explicit API key.
Sourcepub fn auth(&self) -> &AuthProvider
pub fn auth(&self) -> &AuthProvider
Returns the authentication provider.
Sourcepub fn model(&mut self, model: RealtimeModel) -> &mut Self
pub fn model(&mut self, model: RealtimeModel) -> &mut Self
Set the model for the Realtime API.
§Example
use openai_tools::realtime::RealtimeClient;
use openai_tools::common::models::RealtimeModel;
let mut client = RealtimeClient::new();
client.model(RealtimeModel::Gpt4oRealtimePreview);Sourcepub fn model_id(&mut self, model_id: impl Into<String>) -> &mut Self
👎Deprecated since 0.2.0: Use model(RealtimeModel) instead for type safety
pub fn model_id(&mut self, model_id: impl Into<String>) -> &mut Self
model(RealtimeModel) instead for type safetySet the model using a string ID (for backward compatibility).
Prefer using [model] with RealtimeModel enum for type safety.
Sourcepub fn modalities(&mut self, modalities: Vec<Modality>) -> &mut Self
pub fn modalities(&mut self, modalities: Vec<Modality>) -> &mut Self
Set the supported modalities.
Sourcepub fn instructions(&mut self, instructions: impl Into<String>) -> &mut Self
pub fn instructions(&mut self, instructions: impl Into<String>) -> &mut Self
Set the system instructions.
Sourcepub fn input_audio_format(&mut self, format: AudioFormat) -> &mut Self
pub fn input_audio_format(&mut self, format: AudioFormat) -> &mut Self
Set the input audio format.
Sourcepub fn output_audio_format(&mut self, format: AudioFormat) -> &mut Self
pub fn output_audio_format(&mut self, format: AudioFormat) -> &mut Self
Set the output audio format.
Sourcepub fn enable_transcription(&mut self, model: TranscriptionModel) -> &mut Self
pub fn enable_transcription(&mut self, model: TranscriptionModel) -> &mut Self
Enable input audio transcription.
Sourcepub fn transcription(&mut self, config: InputAudioTranscription) -> &mut Self
pub fn transcription(&mut self, config: InputAudioTranscription) -> &mut Self
Set input audio transcription configuration.
Sourcepub fn server_vad(&mut self, config: ServerVadConfig) -> &mut Self
pub fn server_vad(&mut self, config: ServerVadConfig) -> &mut Self
Set Server VAD turn detection.
Sourcepub fn semantic_vad(&mut self, config: SemanticVadConfig) -> &mut Self
pub fn semantic_vad(&mut self, config: SemanticVadConfig) -> &mut Self
Set Semantic VAD turn detection.
Sourcepub fn disable_turn_detection(&mut self) -> &mut Self
pub fn disable_turn_detection(&mut self) -> &mut Self
Disable turn detection (manual mode).
Sourcepub fn tools(&mut self, tools: Vec<Tool>) -> &mut Self
pub fn tools(&mut self, tools: Vec<Tool>) -> &mut Self
Set available tools for function calling.
Accepts Tool from the common module and converts to RealtimeTool.
Sourcepub fn realtime_tools(&mut self, tools: Vec<RealtimeTool>) -> &mut Self
pub fn realtime_tools(&mut self, tools: Vec<RealtimeTool>) -> &mut Self
Set available realtime tools directly.
Sourcepub fn temperature(&mut self, temp: f32) -> &mut Self
pub fn temperature(&mut self, temp: f32) -> &mut Self
Set the sampling temperature.
Sourcepub async fn connect(&self) -> Result<RealtimeSession>
pub async fn connect(&self) -> Result<RealtimeSession>
Connect to the Realtime API.
Returns a RealtimeSession for sending and receiving events.
Trait Implementations§
Source§impl Clone for RealtimeClient
impl Clone for RealtimeClient
Source§fn clone(&self) -> RealtimeClient
fn clone(&self) -> RealtimeClient
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for RealtimeClient
impl Debug for RealtimeClient
Auto Trait Implementations§
impl Freeze for RealtimeClient
impl RefUnwindSafe for RealtimeClient
impl Send for RealtimeClient
impl Sync for RealtimeClient
impl Unpin for RealtimeClient
impl UnwindSafe for RealtimeClient
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§impl<T> Pointable for T
impl<T> Pointable for T
Source§impl<T> PolicyExt for Twhere
T: ?Sized,
impl<T> PolicyExt for Twhere
T: ?Sized,
Source§impl<R, P> ReadPrimitive<R> for P
impl<R, P> ReadPrimitive<R> for P
Source§fn read_from_little_endian(read: &mut R) -> Result<Self, Error>
fn read_from_little_endian(read: &mut R) -> Result<Self, Error>
ReadEndian::read_from_little_endian().