Skip to main content

openai_interface/containers/files/
retrieve.rs

1//! Retrieve a container file via
2//! `GET /containers/{container_id}/files/{file_id}`.
3//!
4//! > ![warn] This module is untested!
5//! > If you encounter any issues, please report them on the repository.
6
7use url::Url;
8
9use crate::{
10    containers::files::ContainerFile,
11    errors::OapiError,
12    rest::get::{Get, GetNoStream},
13};
14
15/// Retrieves a file of a container by its ID.
16#[derive(Debug, Clone)]
17pub struct RetrieveContainerFileRequest<'a> {
18    /// The ID of the container, e.g. `cntr_...`.
19    pub container_id: &'a str,
20    /// The ID of the container file, e.g. `cfile_...`.
21    pub file_id: &'a str,
22}
23
24impl Get for RetrieveContainerFileRequest<'_> {
25    /// Builds the URL for the request.
26    ///
27    /// `base_url` should be like <https://api.openai.com/v1>
28    fn build_url(&self, base_url: &str) -> Result<String, OapiError> {
29        let mut url = Url::parse(base_url.trim_end_matches('/')).map_err(OapiError::UrlError)?;
30        url.path_segments_mut()
31            .map_err(|_| OapiError::UrlCannotBeBase(base_url.to_string()))?
32            .push("containers")
33            .push(self.container_id)
34            .push("files")
35            .push(self.file_id);
36        Ok(url.to_string())
37    }
38}
39
40impl GetNoStream for RetrieveContainerFileRequest<'_> {
41    type Response = ContainerFile;
42}