1use serde::{Deserialize, Serialize};
4use std::collections::HashMap;
5
6#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
8#[serde(rename_all = "snake_case")]
9pub enum BatchStatus {
10 Validating,
12 Failed,
14 InProgress,
16 Finalizing,
18 Completed,
20 Expired,
22 Cancelling,
24 Cancelled,
26}
27
28#[derive(Debug, Clone, Serialize, Deserialize)]
30pub struct BatchRequestCounts {
31 pub total: u32,
33 pub completed: u32,
35 pub failed: u32,
37}
38
39#[derive(Debug, Clone, Serialize, Deserialize)]
41pub struct Batch {
42 pub id: String,
44 pub object: String,
46 pub endpoint: String,
48 pub status: BatchStatus,
50 pub created_at: i64,
52 pub completion_window: String,
54 #[serde(skip_serializing_if = "Option::is_none")]
56 pub provider: Option<String>,
57 #[serde(skip_serializing_if = "Option::is_none")]
59 pub input_file_id: Option<String>,
60 #[serde(skip_serializing_if = "Option::is_none")]
62 pub output_file_id: Option<String>,
63 #[serde(skip_serializing_if = "Option::is_none")]
65 pub error_file_id: Option<String>,
66 #[serde(skip_serializing_if = "Option::is_none")]
68 pub request_counts: Option<BatchRequestCounts>,
69 #[serde(skip_serializing_if = "Option::is_none")]
71 pub metadata: Option<HashMap<String, String>>,
72 #[serde(skip_serializing_if = "Option::is_none")]
74 pub in_progress_at: Option<i64>,
75 #[serde(skip_serializing_if = "Option::is_none")]
77 pub completed_at: Option<i64>,
78}
79
80#[derive(Debug, Clone, Serialize)]
82pub struct CreateBatchParams {
83 pub model: String,
85 pub requests: Vec<BatchRequestItem>,
87 #[serde(skip_serializing_if = "Option::is_none")]
89 pub completion_window: Option<String>,
90 #[serde(skip_serializing_if = "Option::is_none")]
92 pub metadata: Option<HashMap<String, String>>,
93}
94
95impl CreateBatchParams {
96 pub fn new(model: impl Into<String>, requests: Vec<BatchRequestItem>) -> Self {
98 Self {
99 model: model.into(),
100 requests,
101 completion_window: None,
102 metadata: None,
103 }
104 }
105
106 pub fn completion_window(mut self, window: impl Into<String>) -> Self {
108 self.completion_window = Some(window.into());
109 self
110 }
111
112 pub fn metadata(mut self, metadata: HashMap<String, String>) -> Self {
114 self.metadata = Some(metadata);
115 self
116 }
117}
118
119#[derive(Debug, Clone, Serialize, Deserialize)]
121pub struct BatchRequestItem {
122 pub custom_id: String,
124 pub body: serde_json::Value,
126}
127
128#[derive(Debug, Clone, Default)]
130pub struct ListBatchesOptions {
131 pub after: Option<String>,
133 pub limit: Option<u32>,
135}
136
137#[derive(Debug, Clone, Serialize, Deserialize)]
139pub struct BatchResultError {
140 pub code: String,
142 pub message: String,
144}
145
146#[derive(Debug, Clone, Serialize, Deserialize)]
148pub struct BatchResultItem {
149 pub custom_id: String,
151 #[serde(skip_serializing_if = "Option::is_none")]
153 pub result: Option<super::completion::ChatCompletion>,
154 #[serde(skip_serializing_if = "Option::is_none")]
156 pub error: Option<BatchResultError>,
157}
158
159#[derive(Debug, Clone, Serialize, Deserialize)]
161pub struct BatchResult {
162 pub results: Vec<BatchResultItem>,
164}