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