openai_interface/chat/
retrieve.rs

1//! Module for retrieving chat completions from OpenAI API.
2//!
3//! > ![warn] This module is untested!
4//! > If you encounter any issues, please report them on the GitHub repository.
5
6pub mod request {
7    use std::collections::HashMap;
8
9    use url::Url;
10
11    use crate::{
12        errors::OapiError,
13        rest::get::{Get, GetNoStream},
14    };
15
16    /// Get a stored chat completion.
17    ///
18    /// Only Chat Completions that have been created with
19    /// the `store` parameter set to `true` will be returned.
20    pub struct ChatRetrieveRequest {
21        pub completion_id: String,
22        pub extra_query: HashMap<String, String>,
23    }
24
25    impl Get for ChatRetrieveRequest {
26        /// base_url should look like <https://api.openai.com/v1/> (must ends with '/')
27        fn build_url(&self, base_url: &str) -> Result<String, crate::errors::OapiError> {
28            let url = Url::parse(base_url)
29                .map_err(|e| OapiError::UrlError(e))?
30                .join("chat/")
31                .unwrap()
32                .join(&self.completion_id)
33                .map_err(|e| OapiError::UrlError(e))?;
34
35            Ok(url.to_string())
36        }
37    }
38
39    impl GetNoStream for ChatRetrieveRequest {
40        type Response = crate::chat::ChatCompletion;
41    }
42}