1use std::collections::HashMap;
2
3use serde::{Deserialize, Serialize};
4
5use super::assistants::AssistantTool;
6use super::chat::{FunctionCall as ChatFunctionCall, ResponseFormat, ToolChoice as ChatToolChoice};
7
8#[derive(Clone, Debug, Default, Serialize, Deserialize)]
21pub struct CreateRunRequest {
22 pub assistant_id: String,
24
25 #[serde(skip_serializing_if = "Option::is_none")]
27 pub model: Option<String>,
28
29 #[serde(skip_serializing_if = "Option::is_none")]
31 pub instructions: Option<String>,
32
33 #[serde(skip_serializing_if = "Option::is_none")]
35 pub additional_instructions: Option<String>,
36
37 #[serde(skip_serializing_if = "Option::is_none")]
39 pub tools: Option<Vec<AssistantTool>>,
40
41 #[serde(skip_serializing_if = "Option::is_none")]
43 pub metadata: Option<HashMap<String, String>>,
44
45 #[serde(skip_serializing_if = "Option::is_none")]
47 pub temperature: Option<f32>,
48
49 #[serde(skip_serializing_if = "Option::is_none")]
51 pub top_p: Option<f32>,
52
53 #[serde(skip_serializing_if = "Option::is_none")]
55 pub max_prompt_tokens: Option<i32>,
56
57 #[serde(skip_serializing_if = "Option::is_none")]
59 pub max_completion_tokens: Option<i32>,
60
61 #[serde(skip_serializing_if = "Option::is_none")]
63 pub truncation_strategy: Option<TruncationStrategy>,
64
65 #[serde(skip_serializing_if = "Option::is_none")]
67 pub tool_choice: Option<ChatToolChoice>,
68
69 #[serde(skip_serializing_if = "Option::is_none")]
71 pub response_format: Option<ResponseFormat>,
72}
73
74#[derive(Clone, Debug, Default, Serialize, Deserialize)]
76pub struct ModifyRunRequest {
77 #[serde(skip_serializing_if = "Option::is_none")]
79 pub metadata: Option<HashMap<String, String>>,
80}
81
82#[derive(Clone, Debug, Serialize, Deserialize)]
84pub struct SubmitToolOutputsRequest {
85 pub tool_outputs: Vec<ToolOutput>,
87}
88
89#[derive(Clone, Debug, Serialize, Deserialize)]
91pub struct ToolOutput {
92 pub tool_call_id: String,
94
95 pub output: String,
97}
98
99#[derive(Clone, Debug, Serialize, Deserialize)]
101pub struct Run {
102 pub id: String,
104
105 pub object: String,
107
108 pub created_at: i64,
110
111 pub thread_id: String,
113
114 pub assistant_id: String,
116
117 pub status: String,
119
120 pub required_action: Option<RequiredAction>,
122
123 pub last_error: Option<RunError>,
125
126 pub expires_at: Option<i64>,
128
129 pub started_at: Option<i64>,
131
132 pub cancelled_at: Option<i64>,
134
135 pub failed_at: Option<i64>,
137
138 pub completed_at: Option<i64>,
140
141 pub model: String,
143
144 pub instructions: String,
146
147 pub tools: Vec<AssistantTool>,
149
150 pub file_ids: Vec<String>,
152
153 pub metadata: HashMap<String, String>,
155
156 pub usage: Option<RunUsage>,
158
159 pub temperature: Option<f32>,
161
162 pub top_p: Option<f32>,
164
165 pub max_prompt_tokens: Option<i32>,
167
168 pub max_completion_tokens: Option<i32>,
170
171 pub truncation_strategy: Option<TruncationStrategy>,
173
174 pub tool_choice: Option<ChatToolChoice>,
176
177 pub response_format: Option<ResponseFormat>,
179}
180
181#[derive(Clone, Debug, Serialize, Deserialize)]
183pub struct RequiredAction {
184 #[serde(rename = "type")]
186 pub action_type: String,
187
188 pub submit_tool_outputs: SubmitToolOutputs,
190}
191
192#[derive(Clone, Debug, Serialize, Deserialize)]
194pub struct SubmitToolOutputs {
195 pub tool_calls: Vec<ToolCall>,
197}
198
199#[derive(Clone, Debug, Serialize, Deserialize)]
201pub struct ToolCall {
202 pub id: String,
204
205 #[serde(rename = "type")]
207 pub tool_type: String,
208
209 pub function: ChatFunctionCall,
211}
212
213#[derive(Clone, Debug, Serialize, Deserialize)]
215pub struct RunError {
216 pub code: String,
218
219 pub message: String,
221}
222
223#[derive(Clone, Debug, Serialize, Deserialize)]
225pub struct RunUsage {
226 pub completion_tokens: i32,
228
229 pub prompt_tokens: i32,
231
232 pub total_tokens: i32,
234}
235
236#[derive(Clone, Debug, Serialize, Deserialize)]
238#[serde(tag = "type")]
239pub enum TruncationStrategy {
240 #[serde(rename = "auto")]
241 Auto,
242 #[serde(rename = "last_messages")]
243 LastMessages { last_messages: i32 },
244}
245
246#[derive(Clone, Debug, Serialize, Deserialize)]
248pub struct ListRunsResponse {
249 pub object: String,
250 pub data: Vec<Run>,
251 pub first_id: Option<String>,
252 pub last_id: Option<String>,
253 pub has_more: bool,
254}
255
256#[derive(Clone, Debug, Serialize, Deserialize)]
258pub struct RunStep {
259 pub id: String,
261
262 pub object: String,
264
265 pub created_at: i64,
267
268 pub assistant_id: String,
270
271 pub thread_id: String,
273
274 pub run_id: String,
276
277 #[serde(rename = "type")]
279 pub step_type: String,
280
281 pub status: String,
283
284 pub step_details: StepDetails,
286
287 pub last_error: Option<RunError>,
289
290 pub expired_at: Option<i64>,
292
293 pub cancelled_at: Option<i64>,
295
296 pub failed_at: Option<i64>,
298
299 pub completed_at: Option<i64>,
301
302 pub metadata: HashMap<String, String>,
304
305 pub usage: Option<RunUsage>,
307}
308
309#[derive(Clone, Debug, Serialize, Deserialize)]
311#[serde(tag = "type")]
312pub enum StepDetails {
313 #[serde(rename = "message_creation")]
314 MessageCreation { message_creation: MessageCreation },
315 #[serde(rename = "tool_calls")]
316 ToolCalls { tool_calls: Vec<ToolCall> },
317}
318
319#[derive(Clone, Debug, Serialize, Deserialize)]
321pub struct MessageCreation {
322 pub message_id: String,
324}
325
326#[derive(Clone, Debug, Serialize, Deserialize)]
328pub struct ListRunStepsResponse {
329 pub object: String,
330 pub data: Vec<RunStep>,
331 pub first_id: Option<String>,
332 pub last_id: Option<String>,
333 pub has_more: bool,
334}