openai_interface/files/
mod.rs

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