openai-interface 0.10.0

A low-level Rust interface for the OpenAI API
Documentation
//! Retrieve a conversation via `GET /conversations/{conversation_id}`.
//!
//! > ![warn] This module is untested!
//! > If you encounter any issues, please report them on the repository.

use url::Url;

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

/// Retrieves a conversation by its ID.
#[derive(Debug, Clone)]
pub struct RetrieveConversationRequest<'a> {
    /// The ID of the conversation to retrieve, e.g. `conv_...`.
    pub conversation_id: &'a str,
}

impl Get for RetrieveConversationRequest<'_> {
    /// 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("conversations")
            .push(self.conversation_id);
        Ok(url.to_string())
    }
}

impl GetNoStream for RetrieveConversationRequest<'_> {
    type Response = Conversation;
}