openai_interface/conversations/
create.rs1use serde::{Deserialize, Serialize};
7use url::Url;
8
9use crate::{
10 conversations::Conversation,
11 errors::OapiError,
12 rest::post::{Post, PostNoStream},
13};
14
15crate::request_body! {
16 #[derive(Debug, Clone, Serialize, Deserialize, Default)]
18 pub struct CreateConversationRequest {
19 #[serde(skip_serializing_if = "Option::is_none")]
22 pub items: Option<Vec<serde_json::Value>>,
23 #[serde(skip_serializing_if = "Option::is_none")]
26 pub metadata: Option<std::collections::HashMap<String, String>>,
27 }
28}
29
30impl Post for CreateConversationRequest {
31 fn is_streaming(&self) -> bool {
32 false
33 }
34
35 fn build_url(&self, base_url: &str) -> Result<String, OapiError> {
39 let mut url = Url::parse(base_url.trim_end_matches('/')).map_err(OapiError::UrlError)?;
40 url.path_segments_mut()
41 .map_err(|_| OapiError::UrlCannotBeBase(base_url.to_string()))?
42 .push("conversations");
43 Ok(url.to_string())
44 }
45}
46
47impl PostNoStream for CreateConversationRequest {
48 type Response = Conversation;
49}