openai_interface/chat/
delete.rs1pub mod request {
7 use url::Url;
8
9 use crate::{
10 chat::delete::response::ChatCompletionDeleted,
11 errors::OapiError,
12 rest::delete::{Delete, DeleteNoStream},
13 };
14
15 #[derive(Debug, Clone)]
20 pub struct ChatDeleteRequest<'a> {
21 pub completion_id: &'a str,
22 }
23
24 impl Delete for ChatDeleteRequest<'_> {
25 fn build_url(&self, base_url: &str) -> Result<String, crate::errors::OapiError> {
29 let mut url = Url::parse(base_url).map_err(|e| OapiError::UrlError(e))?;
30 url.path_segments_mut()
31 .map_err(|_| OapiError::UrlCannotBeBase(base_url.to_string()))?
32 .push("chat")
33 .push("delete")
34 .push(self.completion_id);
35 Ok(url.to_string())
36 }
37 }
38
39 impl DeleteNoStream for ChatDeleteRequest<'_> {
40 type Response = ChatCompletionDeleted;
41 }
42}
43
44pub mod response {
45 use std::str::FromStr;
46
47 use serde::Deserialize;
48
49 use crate::errors::OapiError;
50
51 #[derive(Debug, Clone, Deserialize)]
52 #[serde(tag = "type")]
53 pub enum ChatCompletionDeleted {
54 #[serde(rename = "chat.completion.deleted")]
56 ChatCompletionDeleted {
57 id: String,
59 deleted: bool,
61 },
62 }
63
64 impl FromStr for ChatCompletionDeleted {
65 type Err = OapiError;
66
67 fn from_str(s: &str) -> Result<Self, Self::Err> {
68 let parse_result: Result<Self, _> =
69 serde_json::from_str(s).map_err(|e| OapiError::DeserializationError(e.to_string()));
70 parse_result
71 }
72 }
73}