Skip to main content

async_openai/types/files/
file.rs

1use derive_builder::Builder;
2use serde::{Deserialize, Serialize};
3
4use crate::error::OpenAIError;
5
6use crate::types::InputSource;
7
8#[derive(Debug, Default, Clone, PartialEq)]
9pub struct FileInput {
10    pub source: InputSource,
11}
12
13#[derive(Debug, Default, Clone, PartialEq)]
14pub enum FilePurpose {
15    Assistants,
16    Batch,
17    #[default]
18    FineTune,
19    Vision,
20    UserData,
21    Evals,
22}
23
24#[derive(Debug, Default, Clone, PartialEq, Deserialize, Serialize)]
25pub enum FileExpirationAfterAnchor {
26    #[default]
27    #[serde(rename = "created_at")]
28    CreatedAt,
29}
30
31#[derive(Debug, Default, Deserialize, Serialize, Clone, PartialEq)]
32pub struct FileExpirationAfter {
33    /// Anchor timestamp after which the expiration policy applies. Supported anchors: `created_at`.
34    pub anchor: FileExpirationAfterAnchor,
35
36    /// The number of seconds after the anchor time that the file will expire. Must be between 3600 (1 hour) and 2592000 (30 days).
37    pub seconds: u32,
38}
39
40#[derive(Debug, Default, Clone, Builder, PartialEq)]
41#[builder(name = "CreateFileRequestArgs")]
42#[builder(pattern = "mutable")]
43#[builder(setter(into, strip_option), default)]
44#[builder(derive(Debug))]
45#[builder(build_fn(error = "OpenAIError"))]
46pub struct CreateFileRequest {
47    /// The File object (not file name) to be uploaded.
48    pub file: FileInput,
49
50    /// The intended purpose of the uploaded file. One of:
51    /// - `assistants`: Used in the Assistants API
52    /// - `batch`: Used in the Batch API
53    /// - `fine-tune`: Used for fine-tuning
54    /// - `vision`: Images used for vision fine-tuning
55    /// - `user_data`: Flexible file type for any purpose
56    /// - `evals`: Used for eval data sets
57    pub purpose: FilePurpose,
58
59    /// The expiration policy for a file. By default, files with `purpose=batch` expire after 30 days and all other files are persisted until they are manually deleted.
60    pub expires_after: Option<FileExpirationAfter>,
61}
62
63#[derive(Debug, Deserialize, Clone, PartialEq, Serialize)]
64pub struct ListFilesResponse {
65    pub object: String,
66    pub data: Vec<OpenAIFile>,
67    pub first_id: Option<String>,
68    pub last_id: Option<String>,
69    pub has_more: bool,
70}
71
72#[derive(Debug, Deserialize, Clone, PartialEq, Serialize)]
73pub struct DeleteFileResponse {
74    pub id: String,
75    pub object: String,
76    pub deleted: bool,
77}
78
79#[derive(Debug, Deserialize, Serialize, Clone, PartialEq)]
80pub enum OpenAIFilePurpose {
81    #[serde(rename = "assistants")]
82    Assistants,
83    #[serde(rename = "assistants_output")]
84    AssistantsOutput,
85    #[serde(rename = "batch")]
86    Batch,
87    #[serde(rename = "batch_output")]
88    BatchOutput,
89    #[serde(rename = "fine-tune")]
90    FineTune,
91    #[serde(rename = "fine-tune-results")]
92    FineTuneResults,
93    #[serde(rename = "vision")]
94    Vision,
95    #[serde(rename = "user_data")]
96    UserData,
97}
98
99/// The `File` object represents a document that has been uploaded to OpenAI.
100#[derive(Debug, Deserialize, Serialize, Clone, PartialEq)]
101pub struct OpenAIFile {
102    /// The file identifier, which can be referenced in the API endpoints.
103    pub id: String,
104    /// The object type, which is always "file".
105    pub object: String,
106    /// The size of the file in bytes.
107    pub bytes: u32,
108    /// The Unix timestamp (in seconds) for when the file was created.
109    pub created_at: u64,
110    /// The Unix timestamp (in seconds) for when the file will expire.
111    pub expires_at: Option<u64>,
112    /// The name of the file.
113    pub filename: String,
114    /// The intended purpose of the file. Supported values are `assistants`, `assistants_output`, `batch`, `batch_output`, `fine-tune`, `fine-tune-results`, `vision`, and `user_data`.
115    pub purpose: OpenAIFilePurpose,
116    /// Deprecated. The current status of the file, which can be either `uploaded`, `processed`, or `error`.
117    #[deprecated]
118    pub status: Option<String>,
119    /// Deprecated. For details on why a fine-tuning training file failed validation, see the `error` field on `fine_tuning.job`.
120    #[deprecated]
121    pub status_details: Option<String>, // nullable: true
122}