Skip to content

Commit bc566e8

Browse files
author
janligudzinski
committed
strongly typed realtime model enum
1 parent d21aef2 commit bc566e8

File tree

2 files changed

+31
-2
lines changed

2 files changed

+31
-2
lines changed

src/realtime/types.rs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,24 @@ pub struct Session {
2626
pub max_output_tokens: Option<MaxOutputTokens>,
2727
}
2828

29+
#[derive(Debug, Serialize, Deserialize, Clone)]
30+
pub enum RealtimeModel {
31+
#[serde(rename = "gpt-realtime")]
32+
GptRealtime,
33+
#[serde(rename = "gpt-4o-realtime-preview")]
34+
Gpt4oRealtimePreview,
35+
#[serde(rename = "gpt-4o-mini-realtime-preview")]
36+
Gpt4oMiniRealtimePreview,
37+
#[serde(rename = "gpt-realtime-2025-08-28")]
38+
GptRealtime20250828,
39+
#[serde(rename = "gpt-4o-realtime-preview-2024-12-17")]
40+
Gpt4oRealtimePreview20241217,
41+
#[serde(rename = "gpt-4o-realtime-preview-2024-10-01")]
42+
Gpt4oRealtimePreview20241001,
43+
#[serde(rename = "gpt-4o-mini-realtime-preview-2024-12-17")]
44+
Gpt4oMiniRealtimePreview20241217,
45+
}
46+
2947
#[derive(Debug, Serialize, Deserialize, Clone)]
3048
#[serde(rename_all = "lowercase")]
3149
pub enum RealtimeVoice {

src/v1/realtime_calls.rs

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,25 @@
11
use serde::{Deserialize, Serialize};
22

3+
use crate::realtime::types::RealtimeModel;
4+
35
/// Used to start a realtime session based on an incoming call that you can then connect to over WSS with `RealtimeSipClient` from `openai_api_rs::realtime::sip`.
46
/// Note that this is poorly documented by OpenAI with the only example data given in https://platform.openai.com/docs/guides/realtime-sip#handle-the-webhook and these may not be all the possible fields.
57
#[derive(Debug, Serialize, Deserialize, Clone)]
68
pub struct AcceptCallRequest {
7-
/// This is *always* `realtime`.
9+
/// This is *always* `realtime`. Convenience constructor exposed to ensure this.
810
#[serde(rename = "type")]
911
pub session_type: String,
1012
pub instructions: String,
11-
pub model: String,
13+
pub model: RealtimeModel,
14+
}
15+
impl AcceptCallRequest {
16+
pub fn new(instructions: String, model: RealtimeModel) -> Self {
17+
Self {
18+
session_type: "realtime".to_string(),
19+
instructions,
20+
model,
21+
}
22+
}
1223
}
1324

1425
/// Used to redirect a call to another number. Per https://platform.openai.com/docs/guides/realtime-sip#handle-the-webhook the Tel-URI scheme may be used.

0 commit comments

Comments
 (0)