async_openai/types/containers/
container.rs

1use derive_builder::Builder;
2use serde::{Deserialize, Serialize};
3
4use crate::error::OpenAIError;
5
6use crate::types::InputSource;
7
8#[derive(Debug, Deserialize, Serialize, Clone, PartialEq, Default)]
9pub enum MemoryLimit {
10    #[default]
11    #[serde(rename = "1g")]
12    OneG,
13    #[serde(rename = "4g")]
14    FourG,
15    #[serde(rename = "16g")]
16    SixteenG,
17    #[serde(rename = "64g")]
18    SixtyFourG,
19}
20
21#[derive(Debug, Deserialize, Serialize, Clone, PartialEq)]
22pub struct ContainerResource {
23    /// Unique identifier for the container.
24    pub id: String,
25    /// The type of this object.
26    pub object: String,
27    /// Name of the container.
28    pub name: String,
29    /// Unix timestamp (in seconds) when the container was created.
30    pub created_at: u64,
31    /// Status of the container (e.g., active, deleted).
32    pub status: String,
33    /// The container will expire after this time period. The anchor is the reference point for the expiration.
34    /// The minutes is the number of minutes after the anchor before the container expires.
35    #[serde(skip_serializing_if = "Option::is_none")]
36    pub expires_after: Option<ContainerExpiresAfter>,
37    /// Unix timestamp (in seconds) when the container was last active.
38    #[serde(skip_serializing_if = "Option::is_none")]
39    pub last_active_at: Option<u64>,
40    /// The memory limit configured for the container.
41    pub memory_limit: MemoryLimit,
42}
43
44/// Expiration policy for containers.
45#[derive(Debug, Deserialize, Serialize, Clone, PartialEq)]
46pub struct ContainerExpiresAfter {
47    /// Time anchor for the expiration time. Currently only 'last_active_at' is supported.
48    pub anchor: ContainerExpiresAfterAnchor,
49    pub minutes: u32,
50}
51
52/// Anchor for container expiration.
53#[derive(Debug, Deserialize, Serialize, Clone, PartialEq)]
54#[serde(rename_all = "snake_case")]
55pub enum ContainerExpiresAfterAnchor {
56    LastActiveAt,
57}
58
59/// Request to create a container.
60/// openapi spec type: CreateContainerBody
61#[derive(Debug, Default, Clone, Builder, PartialEq, Serialize)]
62#[builder(name = "CreateContainerRequestArgs")]
63#[builder(pattern = "mutable")]
64#[builder(setter(into, strip_option), default)]
65#[builder(derive(Debug))]
66#[builder(build_fn(error = "OpenAIError"))]
67pub struct CreateContainerRequest {
68    /// Name of the container to create.
69    pub name: String,
70    /// IDs of files to copy to the container.
71    #[serde(skip_serializing_if = "Option::is_none")]
72    pub file_ids: Option<Vec<String>>,
73    /// Container expiration time in minutes relative to the 'anchor' time.
74    #[serde(skip_serializing_if = "Option::is_none")]
75    pub expires_after: Option<ContainerExpiresAfter>,
76    /// Optional memory limit for the container. Defaults to "1g".
77    #[serde(skip_serializing_if = "Option::is_none")]
78    pub memory_limit: Option<MemoryLimit>,
79}
80
81/// Response when listing containers.
82#[derive(Debug, Deserialize, Serialize, Clone, PartialEq)]
83pub struct ContainerListResource {
84    /// The type of object returned, must be 'list'.
85    pub object: String,
86    /// A list of containers.
87    pub data: Vec<ContainerResource>,
88    /// The ID of the first container in the list.
89    pub first_id: Option<String>,
90    /// The ID of the last container in the list.
91    pub last_id: Option<String>,
92    /// Whether there are more containers available.
93    pub has_more: bool,
94}
95
96/// Response when deleting a container.
97#[derive(Debug, Deserialize, Clone, PartialEq, Serialize)]
98pub struct DeleteContainerResponse {
99    pub id: String,
100    pub object: String,
101    pub deleted: bool,
102}
103
104// Container File types
105
106/// The container file object represents a file in a container.
107#[derive(Debug, Deserialize, Serialize, Clone, PartialEq)]
108pub struct ContainerFileResource {
109    /// Unique identifier for the file.
110    pub id: String,
111    /// The type of this object (`container.file`).
112    pub object: String,
113    /// The container this file belongs to.
114    pub container_id: String,
115    /// Unix timestamp (in seconds) when the file was created.
116    pub created_at: u64,
117    /// Size of the file in bytes.
118    pub bytes: u32,
119    /// Path of the file in the container.
120    pub path: String,
121    /// Source of the file (e.g., `user`, `assistant`).
122    pub source: String,
123}
124
125/// Request to create a container file.
126/// openapi spec type: CreateContainerFileBody
127#[derive(Debug, Default, Clone, PartialEq)]
128pub struct CreateContainerFileRequest {
129    /// The File object (not file name) to be uploaded.
130    pub file: Option<InputSource>,
131    /// Name of the file to create.
132    pub file_id: Option<String>,
133}
134
135/// Response when listing container files.
136#[derive(Debug, Deserialize, Serialize, Clone, PartialEq)]
137pub struct ContainerFileListResource {
138    /// The type of object returned, must be 'list'.
139    pub object: String,
140    /// A list of container files.
141    pub data: Vec<ContainerFileResource>,
142    /// The ID of the first file in the list.
143    pub first_id: Option<String>,
144    /// The ID of the last file in the list.
145    pub last_id: Option<String>,
146    /// Whether there are more files available.
147    pub has_more: bool,
148}
149
150/// Response when deleting a container file.
151#[derive(Debug, Deserialize, Clone, PartialEq, Serialize)]
152pub struct DeleteContainerFileResponse {
153    pub id: String,
154    pub object: String,
155    pub deleted: bool,
156}