1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
/*
* OpenAI API
*
* The OpenAI REST API. Please see https://platform.openai.com/docs/api-reference for more details.
*
* The version of the OpenAPI document: 2.3.0
*
* Generated by: https://openapi-generator.tech
*/
use crate::models;
use serde::{Deserialize, Serialize};
#[derive(Clone, Default, Debug, PartialEq, Serialize, Deserialize, bon::Builder)]
pub struct CreateBatchRequest {
/// The ID of an uploaded file that contains requests for the new batch. See [upload file](/docs/api-reference/files/create) for how to upload a file. Your input file must be formatted as a [JSONL file](/docs/api-reference/batch/request-input), and must be uploaded with the purpose `batch`. The file can contain up to 50,000 requests, and can be up to 200 MB in size.
#[serde(rename = "input_file_id")]
pub input_file_id: String,
/// The endpoint to be used for all requests in the batch. Currently `/v1/responses`, `/v1/chat/completions`, `/v1/embeddings`, `/v1/completions`, `/v1/moderations`, `/v1/images/generations`, `/v1/images/edits`, and `/v1/videos` are supported. Note that `/v1/embeddings` batches are also restricted to a maximum of 50,000 embedding inputs across all requests in the batch.
#[serde(rename = "endpoint")]
pub endpoint: Endpoint,
/// The time frame within which the batch should be processed. Currently only `24h` is supported.
#[serde(rename = "completion_window")]
pub completion_window: CompletionWindow,
/// Set of 16 key-value pairs that can be attached to an object. This can be useful for storing additional information about the object in a structured format, and querying for objects via API or the dashboard. Keys are strings with a maximum length of 64 characters. Values are strings with a maximum length of 512 characters.
#[serde(
rename = "metadata",
default,
with = "::serde_with::rust::double_option",
skip_serializing_if = "Option::is_none"
)]
pub metadata: Option<Option<std::collections::HashMap<String, String>>>,
#[serde(
rename = "output_expires_after",
skip_serializing_if = "Option::is_none"
)]
pub output_expires_after: Option<Box<models::BatchFileExpirationAfter>>,
}
impl CreateBatchRequest {
pub fn new(
input_file_id: String,
endpoint: Endpoint,
completion_window: CompletionWindow,
) -> CreateBatchRequest {
CreateBatchRequest {
input_file_id,
endpoint,
completion_window,
metadata: None,
output_expires_after: None,
}
}
}
/// The endpoint to be used for all requests in the batch. Currently `/v1/responses`, `/v1/chat/completions`, `/v1/embeddings`, `/v1/completions`, `/v1/moderations`, `/v1/images/generations`, `/v1/images/edits`, and `/v1/videos` are supported. Note that `/v1/embeddings` batches are also restricted to a maximum of 50,000 embedding inputs across all requests in the batch.
#[derive(Clone, Copy, Debug, Eq, PartialEq, Ord, PartialOrd, Hash, Serialize, Deserialize)]
pub enum Endpoint {
#[serde(rename = "/v1/responses")]
SlashV1SlashResponses,
#[serde(rename = "/v1/chat/completions")]
SlashV1SlashChatSlashCompletions,
#[serde(rename = "/v1/embeddings")]
SlashV1SlashEmbeddings,
#[serde(rename = "/v1/completions")]
SlashV1SlashCompletions,
#[serde(rename = "/v1/moderations")]
SlashV1SlashModerations,
#[serde(rename = "/v1/images/generations")]
SlashV1SlashImagesSlashGenerations,
#[serde(rename = "/v1/images/edits")]
SlashV1SlashImagesSlashEdits,
#[serde(rename = "/v1/videos")]
SlashV1SlashVideos,
}
impl Default for Endpoint {
fn default() -> Endpoint {
Self::SlashV1SlashResponses
}
}
/// The time frame within which the batch should be processed. Currently only `24h` is supported.
#[derive(Clone, Copy, Debug, Eq, PartialEq, Ord, PartialOrd, Hash, Serialize, Deserialize)]
pub enum CompletionWindow {
#[serde(rename = "24h")]
Variant24h,
}
impl Default for CompletionWindow {
fn default() -> CompletionWindow {
Self::Variant24h
}
}
impl std::fmt::Display for CreateBatchRequest {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match serde_json::to_string(self) {
Ok(s) => write!(f, "{}", s),
Err(_) => Err(std::fmt::Error),
}
}
}