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.
51    ///
52    /// Use "assistants" for [Assistants](https://platform.openai.com/docs/api-reference/assistants) and [Message](https://platform.openai.com/docs/api-reference/messages) files, "vision" for Assistants image file inputs, "batch" for [Batch API](https://platform.openai.com/docs/guides/batch), "fine-tune" for [Fine-tuning](https://platform.openai.com/docs/api-reference/fine-tuning), "user_data" for flexible file type for any purpose, and "evals" for eval data sets.
53    pub purpose: FilePurpose,
54
55    /// 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.
56    pub expires_after: Option<FileExpirationAfter>,
57}
58
59#[derive(Debug, Deserialize, Clone, PartialEq, Serialize)]
60pub struct ListFilesResponse {
61    pub object: String,
62    pub data: Vec<OpenAIFile>,
63    pub first_id: String,
64    pub last_id: String,
65    pub has_more: bool,
66}
67
68#[derive(Debug, Deserialize, Clone, PartialEq, Serialize)]
69pub struct DeleteFileResponse {
70    pub id: String,
71    pub object: String,
72    pub deleted: bool,
73}
74
75#[derive(Debug, Deserialize, Serialize, Clone, PartialEq)]
76pub enum OpenAIFilePurpose {
77    #[serde(rename = "assistants")]
78    Assistants,
79    #[serde(rename = "assistants_output")]
80    AssistantsOutput,
81    #[serde(rename = "batch")]
82    Batch,
83    #[serde(rename = "batch_output")]
84    BatchOutput,
85    #[serde(rename = "fine-tune")]
86    FineTune,
87    #[serde(rename = "fine-tune-results")]
88    FineTuneResults,
89    #[serde(rename = "vision")]
90    Vision,
91    #[serde(rename = "user_data")]
92    UserData,
93}
94
95/// The `File` object represents a document that has been uploaded to OpenAI.
96#[derive(Debug, Deserialize, Serialize, Clone, PartialEq)]
97pub struct OpenAIFile {
98    /// The file identifier, which can be referenced in the API endpoints.
99    pub id: String,
100    /// The object type, which is always "file".
101    pub object: String,
102    /// The size of the file in bytes.
103    pub bytes: u32,
104    /// The Unix timestamp (in seconds) for when the file was created.
105    pub created_at: u32,
106    /// The Unix timestamp (in seconds) for when the file will expire.
107    pub expires_at: Option<u32>,
108    /// The name of the file.
109    pub filename: String,
110    /// The intended purpose of the file. Supported values are `assistants`, `assistants_output`, `batch`, `batch_output`, `fine-tune`, `fine-tune-results`, `vision`, and `user_data`.
111    pub purpose: OpenAIFilePurpose,
112    /// Deprecated. The current status of the file, which can be either `uploaded`, `processed`, or `error`.
113    #[deprecated]
114    pub status: Option<String>,
115    /// Deprecated. For details on why a fine-tuning training file failed validation, see the `error` field on `fine_tuning.job`.
116    #[deprecated]
117    pub status_details: Option<String>, // nullable: true
118}