openai_interface/files/
mod.rs

1//! File management module for OpenAI API integration.
2//!
3//! This module provides functionality for managing files in the OpenAI ecosystem,
4//! including creating, listing, and retrieving file objects. It defines the core
5//! data structures for representing files and their metadata as returned by the
6//! OpenAI API.
7//!
8//! Submodules: `create`, `list`, and `retrieve` for specific file operations
9
10pub mod create;
11pub mod list;
12pub mod retrieve;
13
14use std::str::FromStr;
15
16use serde::Deserialize;
17
18use crate::errors::OapiError;
19
20#[derive(Debug, Deserialize, Clone, PartialEq, Eq)]
21pub struct FileObject {
22    /// The file identifier, which can be referenced in the API endpoints.
23    pub id: String,
24    /// The size of the file, in bytes.
25    pub bytes: usize,
26    /// The Unix timestamp (in seconds) for when the file was created.
27    pub created_at: usize,
28    /// The name of the file.
29    pub filename: String,
30    /// The object type, which is always `file`.
31    pub object: String,
32    /// The intended purpose of the file.
33    /// Supported values are `assistants`, `assistants_output`, `batch`, `batch_output`,
34    /// `fine-tune`, `fine-tune-results`, `vision`, and `user_data`.
35    pub purpose: FilePurpose,
36    /// Deprecated. The current status of the file, which can be either `uploaded`,
37    /// `processed`, or `error`.
38    pub status: Option<FileStatus>,
39    /// The Unix timestamp (in seconds) for when the file will expire.
40    pub expires_at: Option<usize>,
41    /// Deprecated. For details on why a fine-tuning training file failed validation, see the
42    /// `error` field on `fine_tuning.job`.
43    pub status_details: Option<String>,
44}
45
46#[derive(Debug, Deserialize, Clone, PartialEq, Eq)]
47#[serde(rename_all = "lowercase")]
48pub enum FileStatus {
49    Uploaded,
50    Processed,
51    Error,
52}
53
54#[derive(Debug, Deserialize, Clone, PartialEq, Eq)]
55pub enum FilePurpose {
56    #[serde(rename = "assistant")]
57    Assistant,
58    #[serde(rename = "assistants_output")]
59    AssistantsOutput,
60    #[serde(rename = "batch")]
61    Batch,
62    #[serde(rename = "batch_output")]
63    BatchOutput,
64    #[serde(rename = "fine-tune")]
65    FineTune,
66    #[serde(rename = "fine-tune-results")]
67    FineTuneResults,
68    #[serde(rename = "vision")]
69    Vision,
70    #[serde(rename = "user_data")]
71    UserData,
72    #[serde(untagged)]
73    Other(String),
74}
75
76impl FromStr for FileObject {
77    type Err = OapiError;
78
79    fn from_str(s: &str) -> Result<Self, Self::Err> {
80        let parse_result: Result<Self, _> =
81            serde_json::from_str(s).map_err(|e| OapiError::DeserializationError(e.to_string()));
82        parse_result
83    }
84}