openai_tools/realtime/
conversation.rs1use serde::{Deserialize, Serialize};
4
5#[derive(Debug, Clone, Serialize, Deserialize)]
7#[serde(tag = "type", rename_all = "snake_case")]
8pub enum ConversationItem {
9 Message(MessageItem),
11 FunctionCall(FunctionCallItem),
13 FunctionCallOutput(FunctionCallOutputItem),
15}
16
17#[derive(Debug, Clone, Serialize, Deserialize)]
19pub struct MessageItem {
20 #[serde(skip_serializing_if = "Option::is_none")]
22 pub id: Option<String>,
23
24 pub role: MessageRole,
26
27 pub content: Vec<ContentPart>,
29}
30
31impl MessageItem {
32 pub fn user_text(text: impl Into<String>) -> Self {
34 Self { id: None, role: MessageRole::User, content: vec![ContentPart::InputText { text: text.into() }] }
35 }
36
37 pub fn assistant_text(text: impl Into<String>) -> Self {
39 Self { id: None, role: MessageRole::Assistant, content: vec![ContentPart::Text { text: text.into() }] }
40 }
41
42 pub fn system(text: impl Into<String>) -> Self {
44 Self { id: None, role: MessageRole::System, content: vec![ContentPart::InputText { text: text.into() }] }
45 }
46
47 pub fn user_audio(audio_base64: impl Into<String>) -> Self {
49 Self { id: None, role: MessageRole::User, content: vec![ContentPart::InputAudio { audio: audio_base64.into(), transcript: None }] }
50 }
51}
52
53#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
55#[serde(rename_all = "lowercase")]
56pub enum MessageRole {
57 System,
59 User,
61 Assistant,
63}
64
65#[derive(Debug, Clone, Serialize, Deserialize)]
67#[serde(tag = "type", rename_all = "snake_case")]
68pub enum ContentPart {
69 InputText { text: String },
71 InputAudio {
73 audio: String,
74 #[serde(skip_serializing_if = "Option::is_none")]
75 transcript: Option<String>,
76 },
77 Text { text: String },
79 Audio {
81 #[serde(skip_serializing_if = "Option::is_none")]
82 audio: Option<String>,
83 #[serde(skip_serializing_if = "Option::is_none")]
84 transcript: Option<String>,
85 },
86 ItemReference { id: String },
88}
89
90impl ContentPart {
91 pub fn input_text(text: impl Into<String>) -> Self {
93 Self::InputText { text: text.into() }
94 }
95
96 pub fn input_audio(audio_base64: impl Into<String>) -> Self {
98 Self::InputAudio { audio: audio_base64.into(), transcript: None }
99 }
100
101 pub fn text(text: impl Into<String>) -> Self {
103 Self::Text { text: text.into() }
104 }
105}
106
107#[derive(Debug, Clone, Serialize, Deserialize)]
109pub struct FunctionCallItem {
110 #[serde(skip_serializing_if = "Option::is_none")]
112 pub id: Option<String>,
113
114 pub call_id: String,
116
117 pub name: String,
119
120 pub arguments: String,
122}
123
124#[derive(Debug, Clone, Serialize, Deserialize)]
126pub struct FunctionCallOutputItem {
127 #[serde(skip_serializing_if = "Option::is_none")]
129 pub id: Option<String>,
130
131 pub call_id: String,
133
134 pub output: String,
136}
137
138impl FunctionCallOutputItem {
139 pub fn new(call_id: impl Into<String>, output: impl Into<String>) -> Self {
141 Self { id: None, call_id: call_id.into(), output: output.into() }
142 }
143}
144
145#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
147#[serde(rename_all = "snake_case")]
148pub enum ItemStatus {
149 InProgress,
151 Completed,
153 Incomplete,
155}