Skip to content

Commit b5b1b47

Browse files
author
janligudzinski
committed
fix: use enum instead of unit struct for type: "realtime" due to
serialization behavior for unit structs (was written as `null`)
1 parent 01df798 commit b5b1b47

File tree

2 files changed

+8
-6
lines changed

2 files changed

+8
-6
lines changed

src/realtime/types.rs

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

47-
/// Unit struct representing the only possible value for `type` in the accept call payload.
47+
/// Enum representing the only possible value for `type` in the accept call payload.
4848
#[derive(Debug, Serialize, Deserialize, Clone)]
49-
#[serde(rename = "realtime")]
50-
pub struct RealtimeSessionType;
49+
#[serde(rename_all = "lowercase")]
50+
pub enum AcceptCallSessionType {
51+
Realtime,
52+
}
5153

5254
#[derive(Debug, Serialize, Deserialize, Clone)]
5355
#[serde(rename_all = "lowercase")]

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, RealtimeSessionType};
3+
use crate::realtime::types::{AcceptCallSessionType, RealtimeModel};
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: RealtimeSessionType,
11+
pub session_type: AcceptCallSessionType,
1212
pub instructions: String,
1313
pub model: RealtimeModel,
1414
}
1515
impl AcceptCallRequest {
1616
pub fn new(instructions: impl Into<String>, model: RealtimeModel) -> Self {
1717
Self {
18-
session_type: RealtimeSessionType,
18+
session_type: AcceptCallSessionType::Realtime,
1919
instructions: instructions.into(),
2020
model,
2121
}

0 commit comments

Comments
 (0)