use crate::client::OpenAI;
use crate::error::OpenAIError;
pub struct Conversations<'a> {
client: &'a OpenAI,
}
impl<'a> Conversations<'a> {
pub(crate) fn new(client: &'a OpenAI) -> Self {
Self { client }
}
pub async fn create(
&self,
body: &impl serde::Serialize,
) -> Result<serde_json::Value, OpenAIError> {
self.client.post("/conversations", body).await
}
pub async fn retrieve(&self, conversation_id: &str) -> Result<serde_json::Value, OpenAIError> {
self.client
.get(&format!("/conversations/{conversation_id}"))
.await
}
pub async fn update(
&self,
conversation_id: &str,
body: &impl serde::Serialize,
) -> Result<serde_json::Value, OpenAIError> {
self.client
.post(&format!("/conversations/{conversation_id}"), body)
.await
}
pub async fn delete(&self, conversation_id: &str) -> Result<serde_json::Value, OpenAIError> {
self.client
.delete(&format!("/conversations/{conversation_id}"))
.await
}
pub async fn list_items(
&self,
conversation_id: &str,
) -> Result<serde_json::Value, OpenAIError> {
self.client
.get(&format!("/conversations/{conversation_id}/items"))
.await
}
pub async fn create_items(
&self,
conversation_id: &str,
body: &impl serde::Serialize,
) -> Result<serde_json::Value, OpenAIError> {
self.client
.post(&format!("/conversations/{conversation_id}/items"), body)
.await
}
pub async fn retrieve_item(
&self,
conversation_id: &str,
item_id: &str,
) -> Result<serde_json::Value, OpenAIError> {
self.client
.get(&format!("/conversations/{conversation_id}/items/{item_id}"))
.await
}
pub async fn delete_item(
&self,
conversation_id: &str,
item_id: &str,
) -> Result<serde_json::Value, OpenAIError> {
self.client
.delete(&format!("/conversations/{conversation_id}/items/{item_id}"))
.await
}
}