openai_interface/files/
mod.rs

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