openai_rst/file.rs
1//! This module defines the structures and methods for managing files, including uploading, deleting, retrieving, and listing files.
2//! It includes:
3//! - `FileData`: Struct representing the data of a file.
4//! - `FileListResponse`: Struct for the response from a request to list files.
5//! - `FileUploadRequest`: Struct for creating a request to upload a file.
6//! - `FileUploadResponse`: Struct for the response from a file upload request.
7//! - `FileDeleteRequest`: Struct for creating a request to delete a file.
8//! - `FileDeleteResponse`: Struct for the response from a file delete request.
9//! - `FileRetrieveRequest`: Struct for creating a request to retrieve a file.
10//! - `FileRetrieveResponse`: Struct for the response from a file retrieve request.
11//! - `FileRetrieveContentRequest`: Struct for creating a request to retrieve the content of a file.
12//! - `FileRetrieveContentResponse`: Struct for the response from a file content retrieve request.
13
14use serde::{Deserialize, Serialize};
15use std::collections::HashMap;
16
17/// Represents the data of a file.
18#[derive(Debug, Deserialize, Serialize)]
19pub struct FileData {
20 /// Unique identifier for the file.
21 pub id: String,
22 /// Object type, typically "file".
23 pub object: String,
24 /// Size of the file in bytes.
25 pub bytes: i32,
26 /// Timestamp of when the file was created.
27 pub created_at: i64,
28 /// Name of the file.
29 pub filename: String,
30 /// Purpose of the file.
31 pub purpose: String,
32}
33
34/// Represents the response from a request to list files.
35#[derive(Debug, Deserialize, Serialize)]
36pub struct FileListResponse {
37 /// Object type, typically "list".
38 pub object: String,
39 /// List of file data.
40 pub data: Vec<FileData>,
41 /// Optional headers from the response.
42 pub headers: Option<HashMap<String, String>>,
43}
44
45/// Represents a request to upload a file.
46#[derive(Debug, Serialize)]
47pub struct FileUploadRequest {
48 /// Path to the file to be uploaded.
49 pub file: String,
50 /// Purpose of the file.
51 pub purpose: String,
52}
53
54impl FileUploadRequest {
55 /// Creates a new `FileUploadRequest` with the specified file and purpose.
56 pub fn new(file: String, purpose: String) -> Self {
57 Self { file, purpose }
58 }
59}
60
61/// Represents the response from a file upload request.
62#[derive(Debug, Deserialize, Serialize)]
63pub struct FileUploadResponse {
64 /// Unique identifier for the uploaded file.
65 pub id: String,
66 /// Object type, typically "file".
67 pub object: String,
68 /// Size of the file in bytes.
69 pub bytes: i32,
70 /// Timestamp of when the file was created.
71 pub created_at: i64,
72 /// Name of the file.
73 pub filename: String,
74 /// Purpose of the file.
75 pub purpose: String,
76 /// Optional headers from the response.
77 pub headers: Option<HashMap<String, String>>,
78}
79
80/// Represents a request to delete a file.
81#[derive(Debug, Serialize)]
82pub struct FileDeleteRequest {
83 /// Identifier for the file to be deleted.
84 pub file_id: String,
85}
86
87impl FileDeleteRequest {
88 /// Creates a new `FileDeleteRequest` with the specified file ID.
89 pub fn new(file_id: String) -> Self {
90 Self { file_id }
91 }
92}
93
94/// Represents the response from a file delete request.
95#[derive(Debug, Deserialize, Serialize)]
96pub struct FileDeleteResponse {
97 /// Unique identifier for the deleted file.
98 pub id: String,
99 /// Object type, typically "file".
100 pub object: String,
101 /// Indicates whether the file was successfully deleted.
102 pub delete: bool,
103 /// Optional headers from the response.
104 pub headers: Option<HashMap<String, String>>,
105}
106
107/// Represents a request to retrieve a file.
108#[derive(Debug, Serialize)]
109pub struct FileRetrieveRequest {
110 /// Identifier for the file to be retrieved.
111 pub file_id: String,
112}
113
114impl FileRetrieveRequest {
115 /// Creates a new `FileRetrieveRequest` with the specified file ID.
116 pub fn new(file_id: String) -> Self {
117 Self { file_id }
118 }
119}
120
121/// Represents the response from a file retrieve request.
122#[derive(Debug, Deserialize, Serialize)]
123pub struct FileRetrieveResponse {
124 /// Unique identifier for the retrieved file.
125 pub id: String,
126 /// Object type, typically "file".
127 pub object: String,
128 /// Size of the file in bytes.
129 pub bytes: i32,
130 /// Timestamp of when the file was created.
131 pub created_at: i64,
132 /// Name of the file.
133 pub filename: String,
134 /// Purpose of the file.
135 pub purpose: String,
136 /// Optional headers from the response.
137 pub headers: Option<HashMap<String, String>>,
138}
139
140/// Represents a request to retrieve the content of a file.
141#[derive(Debug, Serialize)]
142pub struct FileRetrieveContentRequest {
143 /// Identifier for the file whose content is to be retrieved.
144 pub file_id: String,
145}
146
147impl FileRetrieveContentRequest {
148 /// Creates a new `FileRetrieveContentRequest` with the specified file ID.
149 pub fn new(file_id: String) -> Self {
150 Self { file_id }
151 }
152}
153
154/// Represents the response from a file content retrieve request.
155#[derive(Debug, Deserialize, Serialize)]
156pub struct FileRetrieveContentResponse {
157 /// Unique identifier for the file whose content was retrieved.
158 pub id: String,
159 /// Object type, typically "file".
160 pub object: String,
161 /// Size of the file in bytes.
162 pub bytes: i32,
163 /// Timestamp of when the file was created.
164 pub created_at: i64,
165 /// Name of the file.
166 pub filename: String,
167 /// Purpose of the file.
168 pub purpose: String,
169 /// Optional headers from the response.
170 pub headers: Option<HashMap<String, String>>,
171}