Skip to main content

openai_interface/containers/
create.rs

1//! Create a container via `POST /containers`.
2//!
3//! > ![warn] This module is untested!
4//! > If you encounter any issues, please report them on the repository.
5
6use serde::Serialize;
7use url::Url;
8
9use crate::{
10    containers::Container,
11    errors::OapiError,
12    rest::post::{Post, PostNoStream},
13};
14
15/// Creates a container.
16#[derive(Debug, Clone, Serialize, Default)]
17pub struct CreateContainerRequest {
18    /// The name of the container.
19    #[serde(skip_serializing_if = "Option::is_none")]
20    pub name: Option<String>,
21    /// The IDs of files to seed the container with, as raw JSON (each
22    /// entry a `{"file_id": ...}` or `{"file_id": ..., "expires_after": ...}`).
23    #[serde(skip_serializing_if = "Option::is_none")]
24    pub file_ids: Option<Vec<serde_json::Value>>,
25    /// The expiration policy of the container, as raw JSON
26    /// (`{"anchor": "last_active_at", "minutes": N}`).
27    #[serde(skip_serializing_if = "Option::is_none")]
28    pub expires_after: Option<serde_json::Value>,
29    /// Additional JSON properties flattened into the request body, for
30    /// fields not covered by the typed struct.
31    #[serde(flatten, skip_serializing_if = "Option::is_none")]
32    pub extra_body: Option<serde_json::Map<String, serde_json::Value>>,
33}
34
35impl Post for CreateContainerRequest {
36    fn is_streaming(&self) -> bool {
37        false
38    }
39
40    /// Builds the URL for the request.
41    ///
42    /// `base_url` should be like <https://api.openai.com/v1>
43    fn build_url(&self, base_url: &str) -> Result<String, OapiError> {
44        let mut url = Url::parse(base_url.trim_end_matches('/')).map_err(OapiError::UrlError)?;
45        url.path_segments_mut()
46            .map_err(|_| OapiError::UrlCannotBeBase(base_url.to_string()))?
47            .push("containers");
48        Ok(url.to_string())
49    }
50}
51
52impl PostNoStream for CreateContainerRequest {
53    type Response = Container;
54}