Skip to main content

openai_interface/containers/files/
content.rs

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