openai_interface/files/create/
response.rs

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