dynamo_async_openai/types/
file.rs

1// SPDX-FileCopyrightText: Copyright (c) 2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
2// SPDX-License-Identifier: Apache-2.0
3//
4// Based on https://github.com/64bit/async-openai/ by Himanshu Neema
5// Original Copyright (c) 2022 Himanshu Neema
6// Licensed under MIT License (see ATTRIBUTIONS-Rust.md)
7//
8// Modifications Copyright (c) 2025 NVIDIA CORPORATION & AFFILIATES.
9// Licensed under Apache 2.0
10
11use derive_builder::Builder;
12use serde::{Deserialize, Serialize};
13
14use crate::error::OpenAIError;
15
16use super::InputSource;
17
18#[derive(Debug, Default, Clone, PartialEq)]
19pub struct FileInput {
20    pub source: InputSource,
21}
22
23#[derive(Debug, Default, Clone, PartialEq)]
24pub enum FilePurpose {
25    Assistants,
26    Batch,
27    #[default]
28    FineTune,
29    Vision,
30}
31
32#[derive(Debug, Default, Clone, Builder, PartialEq)]
33#[builder(name = "CreateFileRequestArgs")]
34#[builder(pattern = "mutable")]
35#[builder(setter(into, strip_option), default)]
36#[builder(derive(Debug))]
37#[builder(build_fn(error = "OpenAIError"))]
38pub struct CreateFileRequest {
39    /// The File object (not file name) to be uploaded.
40    pub file: FileInput,
41
42    /// The intended purpose of the uploaded file.
43    ///
44    /// 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).
45    pub purpose: FilePurpose,
46}
47
48#[derive(Debug, Deserialize, Clone, PartialEq, Serialize)]
49pub struct ListFilesResponse {
50    pub object: String,
51    pub data: Vec<OpenAIFile>,
52}
53
54#[derive(Debug, Deserialize, Clone, PartialEq, Serialize)]
55pub struct DeleteFileResponse {
56    pub id: String,
57    pub object: String,
58    pub deleted: bool,
59}
60
61#[derive(Debug, Deserialize, Serialize, Clone, PartialEq)]
62pub enum OpenAIFilePurpose {
63    #[serde(rename = "assistants")]
64    Assistants,
65    #[serde(rename = "assistants_output")]
66    AssistantsOutput,
67    #[serde(rename = "batch")]
68    Batch,
69    #[serde(rename = "batch_output")]
70    BatchOutput,
71    #[serde(rename = "fine-tune")]
72    FineTune,
73    #[serde(rename = "fine-tune-results")]
74    FineTuneResults,
75    #[serde(rename = "vision")]
76    Vision,
77}
78
79/// The `File` object represents a document that has been uploaded to OpenAI.
80#[derive(Debug, Deserialize, Serialize, Clone, PartialEq)]
81pub struct OpenAIFile {
82    /// The file identifier, which can be referenced in the API endpoints.
83    pub id: String,
84    /// The object type, which is always "file".
85    pub object: String,
86    /// The size of the file in bytes.
87    pub bytes: u32,
88    /// The Unix timestamp (in seconds) for when the file was created.
89    pub created_at: u32,
90    /// The name of the file.
91    pub filename: String,
92    /// The intended purpose of the file. Supported values are `assistants`, `assistants_output`, `batch`, `batch_output`, `fine-tune`, `fine-tune-results` and `vision`.
93    pub purpose: OpenAIFilePurpose,
94    /// Deprecated. The current status of the file, which can be either `uploaded`, `processed`, or `error`.
95    #[deprecated]
96    pub status: Option<String>,
97    /// Deprecated. For details on why a fine-tuning training file failed validation, see the `error` field on `fine_tuning.job`.
98    #[deprecated]
99    pub status_details: Option<String>, // nullable: true
100}