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