async_openai/types/realtime/
item.rs

1use serde::{Deserialize, Serialize};
2
3#[derive(Debug, Serialize, Deserialize, Clone)]
4#[serde(rename_all = "snake_case")]
5pub enum ItemType {
6    Message,
7    FunctionCall,
8    FunctionCallOutput,
9}
10
11#[derive(Debug, Serialize, Deserialize, Clone)]
12#[serde(rename_all = "snake_case")]
13pub enum ItemStatus {
14    Completed,
15    InProgress,
16    Incomplete,
17}
18
19#[derive(Debug, Serialize, Deserialize, Clone)]
20#[serde(rename_all = "lowercase")]
21pub enum ItemRole {
22    User,
23    Assistant,
24    System,
25}
26
27#[derive(Debug, Serialize, Deserialize, Clone)]
28#[serde(rename_all = "snake_case")]
29pub enum ItemContentType {
30    InputText,
31    InputAudio,
32    Text,
33    Audio,
34}
35
36#[derive(Debug, Serialize, Deserialize, Clone)]
37pub struct ItemContent {
38    /// The content type ("input_text", "input_audio", "text", "audio").
39    pub r#type: ItemContentType,
40
41    /// The text content.
42    #[serde(skip_serializing_if = "Option::is_none")]
43    pub text: Option<String>,
44
45    /// Base64-encoded audio bytes.
46    #[serde(skip_serializing_if = "Option::is_none")]
47    pub audio: Option<String>,
48
49    /// The transcript of the audio.
50    #[serde(skip_serializing_if = "Option::is_none")]
51    pub transcript: Option<String>,
52}
53
54#[derive(Debug, Serialize, Deserialize, Clone)]
55pub struct Item {
56    /// The unique ID of the item.
57    #[serde(skip_serializing_if = "Option::is_none")]
58    pub id: Option<String>,
59
60    /// The type of the item ("message", "function_call", "function_call_output").
61    #[serde(skip_serializing_if = "Option::is_none")]
62    pub r#type: Option<ItemType>,
63
64    /// The status of the item ("completed", "in_progress", "incomplete").
65    #[serde(skip_serializing_if = "Option::is_none")]
66    pub status: Option<ItemStatus>,
67
68    /// The role of the message sender ("user", "assistant", "system").
69    #[serde(skip_serializing_if = "Option::is_none")]
70    pub role: Option<ItemRole>,
71
72    /// The content of the message.
73    #[serde(skip_serializing_if = "Option::is_none")]
74    pub content: Option<Vec<ItemContent>>,
75
76    /// The ID of the function call (for "function_call" items).
77    #[serde(skip_serializing_if = "Option::is_none")]
78    pub call_id: Option<String>,
79
80    /// The name of the function being called (for "function_call" items).
81    #[serde(skip_serializing_if = "Option::is_none")]
82    pub name: Option<String>,
83
84    /// The arguments of the function call (for "function_call" items).
85    #[serde(skip_serializing_if = "Option::is_none")]
86    pub arguments: Option<String>,
87
88    /// The output of the function call (for "function_call_output" items).
89    #[serde(skip_serializing_if = "Option::is_none")]
90    pub output: Option<String>,
91}
92
93impl TryFrom<serde_json::Value> for Item {
94    type Error = serde_json::Error;
95
96    fn try_from(value: serde_json::Value) -> Result<Self, Self::Error> {
97        serde_json::from_value(value)
98    }
99}