Skip to content

Commit 611f402

Browse files
author
janligudzinski
committed
use one-off unit struct for "type": "realtime" field
1 parent bc566e8 commit 611f402

File tree

2 files changed

+8
-3
lines changed

2 files changed

+8
-3
lines changed

src/realtime/types.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,11 @@ pub enum RealtimeModel {
4444
Gpt4oMiniRealtimePreview20241217,
4545
}
4646

47+
/// Unit struct representing the only possible value for `type` in the accept call payload.
48+
#[derive(Debug, Serialize, Deserialize, Clone)]
49+
#[serde(rename = "realtime")]
50+
pub struct RealtimeSessionType;
51+
4752
#[derive(Debug, Serialize, Deserialize, Clone)]
4853
#[serde(rename_all = "lowercase")]
4954
pub enum RealtimeVoice {

src/v1/realtime_calls.rs

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

3-
use crate::realtime::types::RealtimeModel;
3+
use crate::realtime::types::{RealtimeModel, RealtimeSessionType};
44

55
/// 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`.
66
/// 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.
77
#[derive(Debug, Serialize, Deserialize, Clone)]
88
pub struct AcceptCallRequest {
99
/// This is *always* `realtime`. Convenience constructor exposed to ensure this.
1010
#[serde(rename = "type")]
11-
pub session_type: String,
11+
pub session_type: RealtimeSessionType,
1212
pub instructions: String,
1313
pub model: RealtimeModel,
1414
}
1515
impl AcceptCallRequest {
1616
pub fn new(instructions: String, model: RealtimeModel) -> Self {
1717
Self {
18-
session_type: "realtime".to_string(),
18+
session_type: RealtimeSessionType,
1919
instructions,
2020
model,
2121
}

0 commit comments

Comments
 (0)