openai_interface/chat/
update.rs

1//! Module for updating stored chat completions.
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 serde::Serialize;
10
11    use crate::rest::post::{Post, PostNoStream};
12
13    /// Modify a stored chat completion.
14    ///
15    /// Only Chat Completions that have been created
16    /// with the `store` parameter set to `true` can be modified. Currently, the only
17    /// supported modification is to update the `metadata` field.
18    #[derive(Debug, Serialize, Default, Clone)]
19    pub struct ChatUpdate<'a> {
20        /// Set of 16 key-value pairs that can be attached to an object. This can be useful
21        /// for storing additional information about the object in a structured format, and
22        /// querying for objects via API or the dashboard.
23        ///
24        /// Keys are strings with a maximum length of 64 characters. Values are strings with
25        /// a maximum length of 512 characters.
26        pub metadata: Option<HashMap<&'a str, &'a str>>,
27    }
28
29    impl ChatUpdate<'_> {
30        pub fn build_url(base_url: impl AsRef<str>, completion_id: impl AsRef<str>) -> String {
31            let mut url = url::Url::parse(base_url.as_ref()).expect("Invalid base URL");
32            url.path_segments_mut()
33                .expect("Cannot modify URL path")
34                .push("chat")
35                .push("completions")
36                .push(completion_id.as_ref());
37            url.to_string()
38        }
39    }
40
41    impl Post for ChatUpdate<'_> {
42        fn is_streaming(&self) -> bool {
43            false
44        }
45    }
46
47    impl PostNoStream for ChatUpdate<'_> {
48        type Response = crate::chat::ChatCompletion;
49    }
50}