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