openai_rst/
run.rs

1//! This module defines the structures and methods for creating and modifying runs,
2//! as well as handling run-related requests and responses.
3//! It includes:
4//! - `CreateRunRequest`: Struct for creating a new run with optional parameters.
5//! - `ModifyRunRequest`: Struct for modifying an existing run's metadata.
6//! - `RunObject`: Struct representing a run object with various attributes.
7//! - `ListRun`: Struct for listing multiple runs.
8//! - `CreateThreadAndRunRequest`: Struct for creating a thread and a run simultaneously.
9//! - `RunStepObject`: Struct representing a step within a run.
10//! - `ListRunStep`: Struct for listing multiple run steps.
11//! - `impl_builder_methods!`: Macro for generating builder methods for structs.
12
13use super::thread::CreateThreadRequest;
14use serde::{Deserialize, Serialize};
15use std::collections::HashMap;
16
17use crate::impl_builder_methods;
18
19/// Represents a request to create a new run.
20#[derive(Debug, Serialize, Clone)]
21pub struct CreateRunRequest {
22    /// Identifier for the assistant.
23    assistant_id: String,
24    /// Optional model to be used for the run.
25    #[serde(skip_serializing_if = "Option::is_none")]
26    pub model: Option<String>,
27    /// Optional instructions for the run.
28    #[serde(skip_serializing_if = "Option::is_none")]
29    pub instructions: Option<String>,
30    /// Optional tools to be used during the run.
31    #[serde(skip_serializing_if = "Option::is_none")]
32    pub tools: Option<Vec<HashMap<String, String>>>,
33    /// Optional metadata for the run.
34    #[serde(skip_serializing_if = "Option::is_none")]
35    pub metadata: Option<HashMap<String, String>>,
36}
37
38impl CreateRunRequest {
39    /// Creates a new `CreateRunRequest` with the specified assistant ID.
40    pub fn new(assistant_id: String) -> Self {
41        Self {
42            assistant_id,
43            model: None,
44            instructions: None,
45            tools: None,
46            metadata: None,
47        }
48    }
49}
50
51impl_builder_methods!(
52    CreateRunRequest,
53    model: String,
54    instructions: String,
55    tools: Vec<HashMap<String, String>>,
56    metadata: HashMap<String, String>
57);
58
59/// Represents a request to modify an existing run's metadata.
60#[derive(Debug, Serialize, Clone)]
61pub struct ModifyRunRequest {
62    /// Optional metadata to update in the run.
63    #[serde(skip_serializing_if = "Option::is_none")]
64    pub metadata: Option<HashMap<String, String>>,
65}
66
67impl ModifyRunRequest {
68    /// Creates a new `ModifyRunRequest`.
69    pub fn new() -> Self {
70        Self { metadata: None }
71    }
72}
73
74impl Default for ModifyRunRequest {
75    /// Provides a default implementation for `ModifyRunRequest`.
76    fn default() -> Self {
77        Self::new()
78    }
79}
80
81impl_builder_methods!(
82    ModifyRunRequest,
83    metadata: HashMap<String, String>
84);
85
86/// Represents a run object with various attributes.
87#[derive(Debug, Deserialize, Serialize)]
88pub struct RunObject {
89    /// Unique identifier for the run.
90    pub id: String,
91    /// Object type, typically "run".
92    pub object: String,
93    /// Timestamp of when the run was created.
94    pub created_at: i64,
95    /// Identifier for the associated thread.
96    pub thread_id: String,
97    /// Identifier for the assistant.
98    pub assistant_id: String,
99    /// Status of the run.
100    pub status: String,
101    /// Optional required actions for the run.
102    #[serde(skip_serializing_if = "Option::is_none")]
103    pub required_action: Option<HashMap<String, String>>,
104    /// Optional last error encountered during the run.
105    #[serde(skip_serializing_if = "Option::is_none")]
106    pub last_error: Option<String>,
107    /// Optional expiration timestamp of the run.
108    #[serde(skip_serializing_if = "Option::is_none")]
109    pub expires_at: Option<i64>,
110    /// Optional start timestamp of the run.
111    #[serde(skip_serializing_if = "Option::is_none")]
112    pub started_at: Option<i64>,
113    /// Optional cancellation timestamp of the run.
114    #[serde(skip_serializing_if = "Option::is_none")]
115    pub cancelled_at: Option<i64>,
116    /// Optional failure timestamp of the run.
117    #[serde(skip_serializing_if = "Option::is_none")]
118    pub failed_at: Option<i64>,
119    /// Optional completion timestamp of the run.
120    #[serde(skip_serializing_if = "Option::is_none")]
121    pub completed_at: Option<i64>,
122    /// Model used in the run.
123    pub model: String,
124    /// Optional instructions for the run.
125    pub instructions: Option<String>,
126    /// Tools used during the run.
127    pub tools: Vec<HashMap<String, String>>,
128    /// File IDs associated with the run.
129    pub file_ids: Vec<String>,
130    /// Metadata for the run.
131    pub metadata: HashMap<String, String>,
132    /// Optional headers from the response.
133    pub headers: Option<HashMap<String, String>>,
134}
135
136/// Represents a list of runs.
137#[derive(Debug, Deserialize, Serialize)]
138pub struct ListRun {
139    /// Object type, typically "list".
140    pub object: String,
141    /// List of run objects.
142    pub data: Vec<RunObject>,
143    /// Identifier for the first run in the list.
144    pub first_id: String,
145    /// Identifier for the last run in the list.
146    pub last_id: String,
147    /// Indicates if there are more runs available.
148    pub has_more: bool,
149    /// Optional headers from the response.
150    pub headers: Option<HashMap<String, String>>,
151}
152
153/// Represents a request to create a thread and a run simultaneously.
154#[derive(Debug, Serialize, Clone)]
155pub struct CreateThreadAndRunRequest {
156    /// Identifier for the assistant.
157    pub assistant_id: String,
158    /// Optional request to create a thread.
159    #[serde(skip_serializing_if = "Option::is_none")]
160    pub thread: Option<CreateThreadRequest>,
161    /// Optional model to be used for the run.
162    #[serde(skip_serializing_if = "Option::is_none")]
163    pub model: Option<String>,
164    /// Optional instructions for the run.
165    #[serde(skip_serializing_if = "Option::is_none")]
166    pub instructions: Option<String>,
167    /// Optional tools to be used during the run.
168    #[serde(skip_serializing_if = "Option::is_none")]
169    pub tools: Option<Vec<HashMap<String, String>>>,
170    /// Optional metadata for the run.
171    #[serde(skip_serializing_if = "Option::is_none")]
172    pub metadata: Option<HashMap<String, String>>,
173}
174
175/// Represents a step within a run.
176#[derive(Debug, Deserialize, Serialize, Clone)]
177pub struct RunStepObject {
178    /// Unique identifier for the run step.
179    pub id: String,
180    /// Object type, typically "run_step".
181    pub object: String,
182    /// Timestamp of when the run step was created.
183    pub created_at: i64,
184    /// Identifier for the assistant.
185    pub assistant_id: String,
186    /// Identifier for the associated thread.
187    pub thread_id: String,
188    /// Identifier for the run.
189    pub run_id: String,
190    /// Type of the run step.
191    #[serde(rename = "type")]
192    pub run_step_type: String,
193    /// Status of the run step.
194    pub status: String,
195    /// Details about the run step.
196    pub step_details: HashMap<String, String>,
197    /// Optional last error encountered during the run step.
198    #[serde(skip_serializing_if = "Option::is_none")]
199    pub last_error: Option<String>,
200    /// Optional expiration timestamp of the run step.
201    #[serde(skip_serializing_if = "Option::is_none")]
202    pub expires_at: Option<i64>,
203    /// Optional start timestamp of the run step.
204    #[serde(skip_serializing_if = "Option::is_none")]
205    pub started_at: Option<i64>,
206    /// Optional cancellation timestamp of the run step.
207    #[serde(skip_serializing_if = "Option::is_none")]
208    pub cancelled_at: Option<i64>,
209    /// Optional failure timestamp of the run step.
210    #[serde(skip_serializing_if = "Option::is_none")]
211    pub failed_at: Option<i64>,
212    /// Optional completion timestamp of the run step.
213    #[serde(skip_serializing_if = "Option::is_none")]
214    pub completed_at: Option<i64>,
215    /// Metadata for the run step.
216    pub metadata: HashMap<String, String>,
217    /// Optional headers from the response.
218    pub headers: Option<HashMap<String, String>>,
219}
220
221/// Represents a list of run steps.
222#[derive(Debug, Deserialize, Serialize, Clone)]
223pub struct ListRunStep {
224    /// Object type, typically "list".
225    pub object: String,
226    /// List of run step objects.
227    pub data: Vec<RunStepObject>,
228    /// Identifier for the first run step in the list.
229    pub first_id: String,
230    /// Identifier for the last run step in the list.
231    pub last_id: String,
232    /// Indicates if there are more run steps available.
233    pub has_more: bool,
234    /// Optional headers from the response.
235    pub headers: Option<HashMap<String, String>>,
236}