Skip to main content

openai_interface/conversations/items/
retrieve.rs

1//! Retrieve a conversation item via
2//! `GET /conversations/{conversation_id}/items/{item_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    conversations::items::ConversationItem,
11    errors::OapiError,
12    rest::get::{Get, GetNoStream},
13};
14
15/// Retrieves an item of a conversation by its ID.
16#[derive(Debug, Clone)]
17pub struct RetrieveConversationItemRequest<'a> {
18    /// The ID of the conversation, e.g. `conv_...`.
19    pub conversation_id: &'a str,
20    /// The ID of the item to retrieve.
21    pub item_id: &'a str,
22}
23
24impl Get for RetrieveConversationItemRequest<'_> {
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("conversations")
33            .push(self.conversation_id)
34            .push("items")
35            .push(self.item_id);
36        Ok(url.to_string())
37    }
38}
39
40impl GetNoStream for RetrieveConversationItemRequest<'_> {
41    /// Unknown item types are preserved as
42    /// [`ResponseOutputItem::Other`](crate::responses::ResponseOutputItem::Other)
43    /// inside the wrapped item.
44    type Response = ConversationItem;
45}