async_openai/
conversations.rs1use crate::{
2 config::Config,
3 conversation_items::ConversationItems,
4 error::OpenAIError,
5 types::responses::{
6 ConversationResource, CreateConversationRequest, DeleteConversationResponse,
7 UpdateConversationRequest,
8 },
9 Client,
10};
11
12pub struct Conversations<'c, C: Config> {
13 client: &'c Client<C>,
14}
15
16impl<'c, C: Config> Conversations<'c, C> {
17 pub fn new(client: &'c Client<C>) -> Self {
18 Self { client }
19 }
20
21 pub fn items(&self, conversation_id: &str) -> ConversationItems<'_, C> {
23 ConversationItems::new(self.client, conversation_id)
24 }
25
26 #[crate::byot(T0 = serde::Serialize, R = serde::de::DeserializeOwned)]
28 pub async fn create(
29 &self,
30 request: CreateConversationRequest,
31 ) -> Result<ConversationResource, OpenAIError> {
32 self.client.post("/conversations", request).await
33 }
34
35 #[crate::byot(T0 = std::fmt::Display, R = serde::de::DeserializeOwned)]
37 pub async fn retrieve(
38 &self,
39 conversation_id: &str,
40 ) -> Result<ConversationResource, OpenAIError> {
41 self.client
42 .get(&format!("/conversations/{conversation_id}"))
43 .await
44 }
45
46 #[crate::byot(T0 = std::fmt::Display, R = serde::de::DeserializeOwned)]
48 pub async fn delete(
49 &self,
50 conversation_id: &str,
51 ) -> Result<DeleteConversationResponse, OpenAIError> {
52 self.client
53 .delete(&format!("/conversations/{conversation_id}"))
54 .await
55 }
56
57 #[crate::byot(T0 = std::fmt::Display, T1 = serde::Serialize, R = serde::de::DeserializeOwned)]
59 pub async fn update(
60 &self,
61 conversation_id: &str,
62 request: UpdateConversationRequest,
63 ) -> Result<ConversationResource, OpenAIError> {
64 self.client
65 .post(&format!("/conversations/{conversation_id}"), request)
66 .await
67 }
68}