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, Builder, PartialEq)]
23#[builder(name = "CreateFileRequestArgs")]
24#[builder(pattern = "mutable")]
25#[builder(setter(into, strip_option), default)]
26#[builder(derive(Debug))]
27#[builder(build_fn(error = "OpenAIError"))]
28pub struct CreateFileRequest {
29    /// The File object (not file name) to be uploaded.
30    pub file: FileInput,
31
32    /// The intended purpose of the uploaded file.
33    ///
34    /// 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).
35    pub purpose: FilePurpose,
36}
37
38#[derive(Debug, Deserialize, Clone, PartialEq, Serialize)]
39pub struct ListFilesResponse {
40    pub object: String,
41    pub data: Vec<OpenAIFile>,
42}
43
44#[derive(Debug, Deserialize, Clone, PartialEq, Serialize)]
45pub struct DeleteFileResponse {
46    pub id: String,
47    pub object: String,
48    pub deleted: bool,
49}
50
51#[derive(Debug, Deserialize, Serialize, Clone, PartialEq)]
52pub enum OpenAIFilePurpose {
53    #[serde(rename = "assistants")]
54    Assistants,
55    #[serde(rename = "assistants_output")]
56    AssistantsOutput,
57    #[serde(rename = "batch")]
58    Batch,
59    #[serde(rename = "batch_output")]
60    BatchOutput,
61    #[serde(rename = "fine-tune")]
62    FineTune,
63    #[serde(rename = "fine-tune-results")]
64    FineTuneResults,
65    #[serde(rename = "vision")]
66    Vision,
67}
68
69/// The `File` object represents a document that has been uploaded to OpenAI.
70#[derive(Debug, Deserialize, Serialize, Clone, PartialEq)]
71pub struct OpenAIFile {
72    /// The file identifier, which can be referenced in the API endpoints.
73    pub id: String,
74    /// The object type, which is always "file".
75    pub object: String,
76    /// The size of the file in bytes.
77    pub bytes: u32,
78    /// The Unix timestamp (in seconds) for when the file was created.
79    pub created_at: u32,
80    /// The name of the file.
81    pub filename: String,
82    /// The intended purpose of the file. Supported values are `assistants`, `assistants_output`, `batch`, `batch_output`, `fine-tune`, `fine-tune-results` and `vision`.
83    pub purpose: OpenAIFilePurpose,
84    /// Deprecated. The current status of the file, which can be either `uploaded`, `processed`, or `error`.
85    #[deprecated]
86    pub status: Option<String>,
87    /// Deprecated. For details on why a fine-tuning training file failed validation, see the `error` field on `fine_tuning.job`.
88    #[deprecated]
89    pub status_details: Option<String>, // nullable: true
90}