Skip to main content

novel_openai/spec/responses/
conversation.rs

1use derive_builder::Builder;
2use serde::{Deserialize, Serialize};
3
4use crate::error::OpenAIError;
5use crate::spec::Metadata;
6use crate::spec::responses::{
7    AnyItemReference, CodeInterpreterToolCall, ComputerToolCall, CustomToolCall,
8    CustomToolCallOutput, FileSearchToolCall, ImageGenToolCall, InputFileContent,
9    InputImageContent, InputItem, InputTextContent, LocalShellToolCall, LocalShellToolCallOutput,
10    MCPApprovalRequest, MCPApprovalResponse, MCPListTools, MCPToolCall, OutputTextContent,
11    ReasoningItem, ReasoningTextContent, RefusalContent, WebSearchToolCall,
12};
13
14/// Represents a conversation object.
15#[derive(Clone, Serialize, Debug, Deserialize, PartialEq)]
16pub struct ConversationResource {
17    /// The unique ID of the conversation.
18    pub id: String,
19    /// The object type, which is always `conversation`.
20    pub object: String,
21    /// Set of 16 key-value pairs that can be attached to an object.
22    pub metadata: Metadata,
23    /// The time at which the conversation was created, measured in seconds since the Unix epoch.
24    pub created_at: u64,
25}
26
27/// Request to create a conversation.
28/// openapi spec type: CreateConversationBody
29#[derive(Clone, Serialize, Default, Debug, Deserialize, Builder, PartialEq)]
30#[builder(name = "CreateConversationRequestArgs")]
31#[builder(pattern = "mutable")]
32#[builder(setter(into, strip_option), default)]
33#[builder(derive(Debug))]
34#[builder(build_fn(error = "OpenAIError"))]
35pub struct CreateConversationRequest {
36    /// Set of 16 key-value pairs that can be attached to an object.
37    #[serde(skip_serializing_if = "Option::is_none")]
38    pub metadata: Option<Metadata>,
39
40    /// Initial items to include in the conversation context. You may add up to 20 items at a time.
41    #[serde(skip_serializing_if = "Option::is_none")]
42    pub items: Option<Vec<InputItem>>,
43}
44
45/// Request to update a conversation.
46#[derive(Clone, Serialize, Default, Debug, Deserialize, Builder, PartialEq)]
47#[builder(name = "UpdateConversationRequestArgs")]
48#[builder(pattern = "mutable")]
49#[builder(setter(into, strip_option), default)]
50#[builder(derive(Debug))]
51#[builder(build_fn(error = "OpenAIError"))]
52pub struct UpdateConversationRequest {
53    /// Set of 16 key-value pairs that can be attached to an object.
54    pub metadata: Metadata,
55}
56
57/// Represents a deleted conversation.
58#[derive(Clone, Serialize, Debug, Deserialize, PartialEq)]
59pub struct DeleteConversationResponse {
60    /// The unique ID of the deleted conversation.
61    pub id: String,
62    /// The object type, which is always `conversation.deleted`.
63    pub object: String,
64    /// Whether the conversation was successfully deleted.
65    pub deleted: bool,
66}
67
68/// Request to create conversation items.
69#[derive(Clone, Serialize, Default, Debug, Deserialize, Builder, PartialEq)]
70#[builder(name = "CreateConversationItemsRequestArgs")]
71#[builder(pattern = "mutable")]
72#[builder(setter(into, strip_option), default)]
73#[builder(derive(Debug))]
74#[builder(build_fn(error = "OpenAIError"))]
75pub struct CreateConversationItemsRequest {
76    /// The items to add to the conversation. You may add up to 20 items at a time.
77    pub items: Vec<InputItem>,
78}
79
80/// A list of Conversation items.
81#[derive(Clone, Serialize, Debug, Deserialize, PartialEq)]
82pub struct ConversationItemList {
83    /// The type of object returned, must be `list`.
84    pub object: String,
85    /// A list of conversation items.
86    pub data: Vec<ConversationItem>,
87    /// Whether there are more items available.
88    pub has_more: bool,
89    /// The ID of the first item in the list.
90    pub first_id: Option<String>,
91    /// The ID of the last item in the list.
92    pub last_id: Option<String>,
93}
94
95#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
96#[serde(rename_all = "snake_case")]
97pub enum MessageStatus {
98    InProgress,
99    Incomplete,
100    Completed,
101}
102
103#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
104#[serde(rename_all = "snake_case")]
105pub enum MessageRole {
106    Unknown,
107    User,
108    Assistant,
109    System,
110    Critic,
111    Discriminator,
112    Developer,
113    Tool,
114}
115
116#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
117pub struct TextContent {
118    pub text: String,
119}
120
121#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
122pub struct SummaryTextContent {
123    /// A summary of the reasoning output from the model so far.
124    pub text: String,
125}
126
127#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
128pub struct ComputerScreenContent {
129    /// The URL of the screenshot image.
130    pub image_url: Option<String>,
131    ///  The identifier of an uploaded file that contains the screenshot.
132    pub file_id: Option<String>,
133}
134
135#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
136#[serde(tag = "type", rename_all = "snake_case")]
137pub enum MessageContent {
138    InputText(InputTextContent),
139    OutputText(OutputTextContent),
140    Text(TextContent),
141    SummaryText(SummaryTextContent),
142    ReasoningText(ReasoningTextContent),
143    Refusal(RefusalContent),
144    InputImage(InputImageContent),
145    ComputerScreen(ComputerScreenContent),
146    InputFile(InputFileContent),
147}
148
149#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
150pub struct Message {
151    /// The unique ID of the message.
152    pub id: String,
153    /// The status of item. One of `in_progress`, `completed`, or `incomplete`. Populated when
154    /// items are returned via API.
155    pub status: MessageStatus,
156    /// The role of the message. One of `unknown`, `user`, `assistant`, `system`, `critic`,
157    /// `discriminator`, `developer`, or `tool`.
158    pub role: MessageRole,
159    /// The content of the message.
160    pub content: Vec<MessageContent>,
161}
162
163#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
164#[serde(tag = "type", rename_all = "snake_case")]
165pub enum ConversationItem {
166    Message(Message),
167    FileSearchCall(FileSearchToolCall),
168    WebSearchCall(WebSearchToolCall),
169    ImageGenerationCall(ImageGenToolCall),
170    ComputerCall(ComputerToolCall),
171    Reasoning(ReasoningItem),
172    CodeInterpreterCall(CodeInterpreterToolCall),
173    LocalShellCall(LocalShellToolCall),
174    LocalShellCallOutput(LocalShellToolCallOutput),
175    McpListTools(MCPListTools),
176    McpApprovalRequest(MCPApprovalRequest),
177    McpApprovalResponse(MCPApprovalResponse),
178    McpCall(MCPToolCall),
179    CustomToolCall(CustomToolCall),
180    CustomToolCallOutput(CustomToolCallOutput),
181    #[serde(untagged)]
182    ItemReference(AnyItemReference),
183}
184
185/// Additional fields to include in the response.
186#[derive(Clone, Serialize, Debug, Deserialize, PartialEq)]
187#[serde(rename_all = "snake_case")]
188pub enum IncludeParam {
189    /// Include the sources of the web search tool call.
190    #[serde(rename = "web_search_call.action.sources")]
191    WebSearchCallActionSources,
192    /// Include the outputs of python code execution in code interpreter tool call items.
193    #[serde(rename = "code_interpreter_call.outputs")]
194    CodeInterpreterCallOutputs,
195    /// Include image urls from the computer call output.
196    #[serde(rename = "computer_call_output.output.image_url")]
197    ComputerCallOutputOutputImageUrl,
198    /// Include the search results of the file search tool call.
199    #[serde(rename = "file_search_call.results")]
200    FileSearchCallResults,
201    /// Include image urls from the input message.
202    #[serde(rename = "message.input_image.image_url")]
203    MessageInputImageImageUrl,
204    /// Include logprobs with assistant messages.
205    #[serde(rename = "message.output_text.logprobs")]
206    MessageOutputTextLogprobs,
207    /// Include an encrypted version of reasoning tokens in reasoning item outputs.
208    #[serde(rename = "reasoning.encrypted_content")]
209    ReasoningEncryptedContent,
210}
211
212/// The order to return items in.
213#[derive(Clone, Serialize, Debug, Deserialize, PartialEq)]
214#[serde(rename_all = "lowercase")]
215pub enum ListOrder {
216    /// Return items in ascending order.
217    Asc,
218    /// Return items in descending order.
219    Desc,
220}