Skip to main content

novel_openai/spec/files/
file.rs

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