openai-interface 0.10.0

A low-level Rust interface for the OpenAI API
Documentation
//! Retrieve the raw content of a container file via
//! `GET /containers/{container_id}/files/{file_id}/content`.
//!
//! > ![warn] This module is untested!
//! > If you encounter any issues, please report them on the repository.
//!
//! The response body is the raw file bytes, so the request is issued
//! through [`GetBinary`](crate::rest::get::GetBinary).

use url::Url;

use crate::{errors::OapiError, rest::get::Get};

/// Retrieves the raw bytes of a container file.
#[derive(Debug, Clone)]
pub struct ContainerFileContentRequest<'a> {
    /// The ID of the container, e.g. `cntr_...`.
    pub container_id: &'a str,
    /// The ID of the container file, e.g. `cfile_...`.
    pub file_id: &'a str,
}

impl Get for ContainerFileContentRequest<'_> {
    /// Builds the URL for the request.
    ///
    /// `base_url` should be like <https://api.openai.com/v1>
    fn build_url(&self, base_url: &str) -> Result<String, OapiError> {
        let mut url = Url::parse(base_url.trim_end_matches('/')).map_err(OapiError::UrlError)?;
        url.path_segments_mut()
            .map_err(|_| OapiError::UrlCannotBeBase(base_url.to_string()))?
            .push("containers")
            .push(self.container_id)
            .push("files")
            .push(self.file_id)
            .push("content");
        Ok(url.to_string())
    }
}