Skip to main content

floopy/types/
files.rs

1use serde::Deserialize;
2
3/// A file stored on the upstream provider. v1 targets the `batch` purpose
4/// (JSONL input + output files). Mirrors the OpenAI file shape; the gateway
5/// forwards file traffic verbatim.
6#[derive(Debug, Clone, Deserialize)]
7pub struct FileObject {
8    /// Provider-issued file id.
9    pub id: String,
10    /// Object type (usually `"file"`).
11    #[serde(default)]
12    pub object: Option<String>,
13    /// File size in bytes.
14    #[serde(default)]
15    pub bytes: Option<i64>,
16    /// Unix creation timestamp.
17    #[serde(default)]
18    pub created_at: Option<i64>,
19    /// Original filename.
20    #[serde(default)]
21    pub filename: Option<String>,
22    /// Upload purpose (e.g. `"batch"`).
23    #[serde(default)]
24    pub purpose: Option<String>,
25    /// Processing status.
26    #[serde(default)]
27    pub status: Option<String>,
28    /// Present (and `true`) on a delete response.
29    #[serde(default)]
30    pub deleted: Option<bool>,
31}
32
33/// Response of [`crate::resources::Files::list`].
34#[derive(Debug, Clone, Deserialize)]
35pub struct FileList {
36    /// Object type (usually `"list"`).
37    #[serde(default)]
38    pub object: Option<String>,
39    /// The files.
40    #[serde(default)]
41    pub data: Vec<FileObject>,
42}
43
44/// Arguments for [`crate::resources::Files::upload`].
45#[derive(Debug, Clone)]
46pub struct FileUploadParams {
47    /// Raw file content (forwarded verbatim as a multipart part).
48    pub file: Vec<u8>,
49    /// Filename used in the multipart part. Defaults to `"file"`.
50    pub filename: Option<String>,
51    /// Upload purpose. Use `"batch"` for batch input files.
52    pub purpose: String,
53}
54
55/// Filters for [`crate::resources::Files::list`].
56#[derive(Debug, Clone, Default)]
57pub struct FileListParams {
58    /// Restrict to a single purpose.
59    pub purpose: Option<String>,
60    /// Page size.
61    pub limit: Option<u32>,
62    /// Cursor: return files after this id.
63    pub after: Option<String>,
64}
65
66impl FileListParams {
67    pub(crate) fn query(&self) -> Vec<(String, String)> {
68        let mut q = Vec::new();
69        if let Some(p) = &self.purpose {
70            q.push(("purpose".to_owned(), p.clone()));
71        }
72        if let Some(l) = self.limit {
73            q.push(("limit".to_owned(), l.to_string()));
74        }
75        if let Some(a) = &self.after {
76            q.push(("after".to_owned(), a.clone()));
77        }
78        q
79    }
80}