openai_types/batch/
manual.rs1use serde::{Deserialize, Serialize};
4
5#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
7#[cfg_attr(feature = "structured", derive(schemars::JsonSchema))]
8#[non_exhaustive]
9pub enum BatchStatus {
10 #[serde(rename = "validating")]
11 Validating,
12 #[serde(rename = "failed")]
13 Failed,
14 #[serde(rename = "in_progress")]
15 InProgress,
16 #[serde(rename = "finalizing")]
17 Finalizing,
18 #[serde(rename = "completed")]
19 Completed,
20 #[serde(rename = "expired")]
21 Expired,
22 #[serde(rename = "cancelling")]
23 Cancelling,
24 #[serde(rename = "cancelled")]
25 Cancelled,
26}
27
28#[derive(Debug, Clone, Serialize)]
30#[cfg_attr(feature = "structured", derive(schemars::JsonSchema))]
31pub struct BatchCreateRequest {
32 pub input_file_id: String,
34
35 pub endpoint: String,
37
38 pub completion_window: String,
40
41 #[serde(skip_serializing_if = "Option::is_none")]
43 pub metadata: Option<std::collections::HashMap<String, String>>,
44}
45
46impl BatchCreateRequest {
47 pub fn new(
48 input_file_id: impl Into<String>,
49 endpoint: impl Into<String>,
50 completion_window: impl Into<String>,
51 ) -> Self {
52 Self {
53 input_file_id: input_file_id.into(),
54 endpoint: endpoint.into(),
55 completion_window: completion_window.into(),
56 metadata: None,
57 }
58 }
59}
60
61#[derive(Debug, Clone, Deserialize)]
63#[cfg_attr(feature = "structured", derive(schemars::JsonSchema))]
64pub struct Batch {
65 pub id: String,
66 pub object: String,
67 pub endpoint: String,
68 pub input_file_id: String,
69 pub completion_window: String,
70 pub status: BatchStatus,
71 pub created_at: i64,
72 #[serde(default)]
73 pub output_file_id: Option<String>,
74 #[serde(default)]
75 pub error_file_id: Option<String>,
76 #[serde(default)]
77 pub in_progress_at: Option<i64>,
78 #[serde(default)]
79 pub completed_at: Option<i64>,
80 #[serde(default)]
81 pub failed_at: Option<i64>,
82 #[serde(default)]
83 pub cancelled_at: Option<i64>,
84 #[serde(default)]
85 pub expired_at: Option<i64>,
86 #[serde(default)]
87 pub request_counts: Option<BatchRequestCounts>,
88 #[serde(default)]
89 pub metadata: Option<std::collections::HashMap<String, String>>,
90}
91
92#[derive(Debug, Clone, Deserialize)]
94#[cfg_attr(feature = "structured", derive(schemars::JsonSchema))]
95pub struct BatchRequestCounts {
96 pub total: i64,
97 pub completed: i64,
98 pub failed: i64,
99}
100
101#[derive(Debug, Clone, Deserialize)]
103#[cfg_attr(feature = "structured", derive(schemars::JsonSchema))]
104pub struct BatchList {
105 pub object: String,
106 pub data: Vec<Batch>,
107 #[serde(default)]
109 pub has_more: Option<bool>,
110 #[serde(default)]
112 pub first_id: Option<String>,
113 #[serde(default)]
115 pub last_id: Option<String>,
116}
117
118#[derive(Debug, Clone, Default)]
120#[cfg_attr(feature = "structured", derive(schemars::JsonSchema))]
121pub struct BatchListParams {
122 pub after: Option<String>,
124 pub limit: Option<i64>,
126}
127
128impl BatchListParams {
129 pub fn new() -> Self {
130 Self::default()
131 }
132
133 pub fn after(mut self, after: impl Into<String>) -> Self {
134 self.after = Some(after.into());
135 self
136 }
137
138 pub fn limit(mut self, limit: i64) -> Self {
139 self.limit = Some(limit);
140 self
141 }
142
143 pub fn to_query(&self) -> Vec<(String, String)> {
145 let mut q = Vec::new();
146 if let Some(ref after) = self.after {
147 q.push(("after".into(), after.clone()));
148 }
149 if let Some(limit) = self.limit {
150 q.push(("limit".into(), limit.to_string()));
151 }
152 q
153 }
154}