dynamo_async_openai/
assistants.rs1use serde::Serialize;
12
13use crate::{
14 config::Config,
15 error::OpenAIError,
16 types::{
17 AssistantObject, CreateAssistantRequest, DeleteAssistantResponse, ListAssistantsResponse,
18 ModifyAssistantRequest,
19 },
20 Client,
21};
22
23pub struct Assistants<'c, C: Config> {
27 client: &'c Client<C>,
28}
29
30impl<'c, C: Config> Assistants<'c, C> {
31 pub fn new(client: &'c Client<C>) -> Self {
32 Self { client }
33 }
34
35 #[crate::byot(T0 = serde::Serialize, R = serde::de::DeserializeOwned)]
37 pub async fn create(
38 &self,
39 request: CreateAssistantRequest,
40 ) -> Result<AssistantObject, OpenAIError> {
41 self.client.post("/assistants", request).await
42 }
43
44 #[crate::byot(T0 = std::fmt::Display, R = serde::de::DeserializeOwned)]
46 pub async fn retrieve(&self, assistant_id: &str) -> Result<AssistantObject, OpenAIError> {
47 self.client
48 .get(&format!("/assistants/{assistant_id}"))
49 .await
50 }
51
52 #[crate::byot(T0 = std::fmt::Display, T1 = serde::Serialize, R = serde::de::DeserializeOwned)]
54 pub async fn update(
55 &self,
56 assistant_id: &str,
57 request: ModifyAssistantRequest,
58 ) -> Result<AssistantObject, OpenAIError> {
59 self.client
60 .post(&format!("/assistants/{assistant_id}"), request)
61 .await
62 }
63
64 #[crate::byot(T0 = std::fmt::Display, R = serde::de::DeserializeOwned)]
66 pub async fn delete(&self, assistant_id: &str) -> Result<DeleteAssistantResponse, OpenAIError> {
67 self.client
68 .delete(&format!("/assistants/{assistant_id}"))
69 .await
70 }
71
72 #[crate::byot(T0 = serde::Serialize, R = serde::de::DeserializeOwned)]
74 pub async fn list<Q>(&self, query: &Q) -> Result<ListAssistantsResponse, OpenAIError>
75 where
76 Q: Serialize + ?Sized,
77 {
78 self.client.get_with_query("/assistants", &query).await
79 }
80}