async_openai/types/
file.rs

1use derive_builder::Builder;
2use serde::{Deserialize, Serialize};
3
4use crate::error::OpenAIError;
5
6use super::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}
21
22#[derive(Debug, Default, Clone, PartialEq, Deserialize, Serialize)]
23pub enum FileExpiresAfterAnchor {
24    #[default]
25    #[serde(rename = "created_at")]
26    CreatedAt
27}
28
29#[derive(Debug, Default, Clone, PartialEq)]
30pub struct FileExpiresAfter {
31    /// Anchor timestamp after which the expiration policy applies. Supported anchors: `created_at`.
32    pub anchor: FileExpiresAfterAnchor,
33
34    /// The number of seconds after the anchor time that the file will expire. Must be between 3600 (1 hour) and 2592000 (30 days).
35    pub seconds: u32,
36}
37
38#[derive(Debug, Default, Clone, Builder, PartialEq)]
39#[builder(name = "CreateFileRequestArgs")]
40#[builder(pattern = "mutable")]
41#[builder(setter(into, strip_option), default)]
42#[builder(derive(Debug))]
43#[builder(build_fn(error = "OpenAIError"))]
44pub struct CreateFileRequest {
45    /// The File object (not file name) to be uploaded.
46    pub file: FileInput,
47
48    /// The intended purpose of the uploaded file.
49    ///
50    /// 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), and "fine-tune" for [Fine-tuning](https://platform.openai.com/docs/api-reference/fine-tuning).
51    pub purpose: FilePurpose,
52
53    /// 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.
54    pub expires_after: Option<FileExpiresAfter>,
55}
56
57#[derive(Debug, Deserialize, Clone, PartialEq, Serialize)]
58pub struct ListFilesResponse {
59    pub object: String,
60    pub data: Vec<OpenAIFile>,
61}
62
63#[derive(Debug, Deserialize, Clone, PartialEq, Serialize)]
64pub struct DeleteFileResponse {
65    pub id: String,
66    pub object: String,
67    pub deleted: bool,
68}
69
70#[derive(Debug, Deserialize, Serialize, Clone, PartialEq)]
71pub enum OpenAIFilePurpose {
72    #[serde(rename = "assistants")]
73    Assistants,
74    #[serde(rename = "assistants_output")]
75    AssistantsOutput,
76    #[serde(rename = "batch")]
77    Batch,
78    #[serde(rename = "batch_output")]
79    BatchOutput,
80    #[serde(rename = "fine-tune")]
81    FineTune,
82    #[serde(rename = "fine-tune-results")]
83    FineTuneResults,
84    #[serde(rename = "vision")]
85    Vision,
86}
87
88/// The `File` object represents a document that has been uploaded to OpenAI.
89#[derive(Debug, Deserialize, Serialize, Clone, PartialEq)]
90pub struct OpenAIFile {
91    /// The file identifier, which can be referenced in the API endpoints.
92    pub id: String,
93    /// The object type, which is always "file".
94    pub object: String,
95    /// The size of the file in bytes.
96    pub bytes: u32,
97    /// The Unix timestamp (in seconds) for when the file was created.
98    pub created_at: u32,
99    /// The Unix timestamp (in seconds) for when the file will expire.
100    pub expires_at: Option<u32>,
101    /// The name of the file.
102    pub filename: String,
103    /// The intended purpose of the file. Supported values are `assistants`, `assistants_output`, `batch`, `batch_output`, `fine-tune`, `fine-tune-results` and `vision`.
104    pub purpose: OpenAIFilePurpose,
105    /// Deprecated. The current status of the file, which can be either `uploaded`, `processed`, or `error`.
106    #[deprecated]
107    pub status: Option<String>,
108    /// Deprecated. For details on why a fine-tuning training file failed validation, see the `error` field on `fine_tuning.job`.
109    #[deprecated]
110    pub status_details: Option<String>, // nullable: true
111}