Skip to main content

openai_interface/conversations/
update.rs

1//! Update a conversation via `POST /conversations/{conversation_id}`.
2//!
3//! > ![warn] This module is untested!
4//! > If you encounter any issues, please report them on the repository.
5
6use serde::Serialize;
7use url::Url;
8
9use crate::{
10    conversations::Conversation,
11    errors::OapiError,
12    rest::post::{Post, PostNoStream},
13};
14
15/// Updates a conversation.
16#[derive(Debug, Clone, Serialize, Default)]
17pub struct UpdateConversationRequest<'a> {
18    /// The ID of the conversation to update, e.g. `conv_...`.
19    #[serde(skip)]
20    pub conversation_id: &'a str,
21    /// The new metadata of the conversation. Passing `null` at the
22    /// JSON level (injectable through `extra_body`) clears it.
23    #[serde(skip_serializing_if = "Option::is_none")]
24    pub metadata: Option<std::collections::HashMap<String, String>>,
25    /// Additional JSON properties flattened into the request body, for
26    /// fields not covered by the typed struct.
27    #[serde(flatten, default, skip_serializing_if = "Option::is_none")]
28    pub extra_body_map: Option<serde_json::Map<String, serde_json::Value>>,
29}
30
31impl Post for UpdateConversationRequest<'_> {
32    fn is_streaming(&self) -> bool {
33        false
34    }
35
36    /// Builds the URL for the request.
37    ///
38    /// `base_url` should be like <https://api.openai.com/v1>
39    fn build_url(&self, base_url: &str) -> Result<String, OapiError> {
40        let mut url = Url::parse(base_url.trim_end_matches('/')).map_err(OapiError::UrlError)?;
41        url.path_segments_mut()
42            .map_err(|_| OapiError::UrlCannotBeBase(base_url.to_string()))?
43            .push("conversations")
44            .push(self.conversation_id);
45        Ok(url.to_string())
46    }
47}
48
49impl PostNoStream for UpdateConversationRequest<'_> {
50    type Response = Conversation;
51}