async_openai_wasm/
assistants.rs1use serde::Serialize;
2
3use crate::{
4 Client,
5 config::Config,
6 error::OpenAIError,
7 types::{
8 AssistantObject, CreateAssistantRequest, DeleteAssistantResponse, ListAssistantsResponse,
9 ModifyAssistantRequest,
10 },
11};
12
13pub struct Assistants<'c, C: Config> {
17 client: &'c Client<C>,
18}
19
20impl<'c, C: Config> Assistants<'c, C> {
21 pub fn new(client: &'c Client<C>) -> Self {
22 Self { client }
23 }
24
25 #[crate::byot(T0 = serde::Serialize, R = serde::de::DeserializeOwned)]
27 pub async fn create(
28 &self,
29 request: CreateAssistantRequest,
30 ) -> Result<AssistantObject, OpenAIError> {
31 self.client.post("/assistants", request).await
32 }
33
34 #[crate::byot(T0 = std::fmt::Display, R = serde::de::DeserializeOwned)]
36 pub async fn retrieve(&self, assistant_id: &str) -> Result<AssistantObject, OpenAIError> {
37 self.client
38 .get(&format!("/assistants/{assistant_id}"))
39 .await
40 }
41
42 #[crate::byot(T0 = std::fmt::Display, T1 = serde::Serialize, R = serde::de::DeserializeOwned)]
44 pub async fn update(
45 &self,
46 assistant_id: &str,
47 request: ModifyAssistantRequest,
48 ) -> Result<AssistantObject, OpenAIError> {
49 self.client
50 .post(&format!("/assistants/{assistant_id}"), request)
51 .await
52 }
53
54 #[crate::byot(T0 = std::fmt::Display, R = serde::de::DeserializeOwned)]
56 pub async fn delete(&self, assistant_id: &str) -> Result<DeleteAssistantResponse, OpenAIError> {
57 self.client
58 .delete(&format!("/assistants/{assistant_id}"))
59 .await
60 }
61
62 #[crate::byot(T0 = serde::Serialize, R = serde::de::DeserializeOwned)]
64 pub async fn list<Q>(&self, query: &Q) -> Result<ListAssistantsResponse, OpenAIError>
65 where
66 Q: Serialize + ?Sized,
67 {
68 self.client.get_with_query("/assistants", &query).await
69 }
70}