openai_api_rs/v1/
batch.rs

1use serde::{Deserialize, Serialize};
2
3#[derive(Debug, Serialize, Deserialize)]
4pub struct CreateBatchRequest {
5    pub input_file_id: String,
6    pub endpoint: String,
7    pub completion_window: String,
8    #[serde(skip_serializing_if = "Option::is_none")]
9    pub metadata: Option<Metadata>,
10}
11
12#[derive(Debug, Serialize, Deserialize)]
13pub struct Metadata {
14    pub customer_id: String,
15    pub batch_description: String,
16}
17
18#[derive(Debug, Serialize, Deserialize)]
19pub struct RequestCounts {
20    pub total: u32,
21    pub completed: u32,
22    pub failed: u32,
23}
24
25#[derive(Debug, Serialize, Deserialize)]
26pub struct BatchError {
27    pub code: String,
28    pub line: Option<u32>,
29    pub message: String,
30    pub param: Option<String>,
31}
32
33#[derive(Debug, Serialize, Deserialize)]
34pub struct BatchErrors {
35    pub object: String,
36    pub data: Vec<BatchError>,
37}
38
39#[derive(Debug, Serialize, Deserialize)]
40pub struct BatchResponse {
41    pub cancelled_at: Option<u64>,
42    pub cancelling_at: Option<u64>,
43    pub completed_at: Option<u64>,
44    pub completion_window: String,
45    pub created_at: u64,
46    pub endpoint: String,
47    pub error_file_id: Option<String>,
48    pub errors: Option<BatchErrors>,
49    pub expired_at: Option<u64>,
50    pub expires_at: Option<u64>,
51    pub failed_at: Option<u64>,
52    pub finalizing_at: Option<u64>,
53    pub id: String,
54    pub in_progress_at: Option<u64>,
55    pub input_file_id: String,
56    pub metadata: Option<Metadata>,
57    pub object: String,
58    pub output_file_id: Option<String>,
59    pub request_counts: RequestCounts,
60    pub status: String,
61}
62
63#[derive(Debug, Serialize, Deserialize)]
64pub struct ListBatchResponse {
65    pub object: String,
66    pub data: Vec<BatchResponse>,
67    pub first_id: String,
68    pub last_id: String,
69    pub has_more: bool,
70}
71
72impl CreateBatchRequest {
73    pub fn new(input_file_id: String, endpoint: String, completion_window: String) -> Self {
74        Self {
75            input_file_id,
76            endpoint,
77            completion_window,
78            metadata: None,
79        }
80    }
81}