async_openai/assistants/
assistants_.rs1use crate::{
2 config::Config,
3 error::OpenAIError,
4 types::assistants::{
5 AssistantObject, CreateAssistantRequest, DeleteAssistantResponse, ListAssistantsResponse,
6 ModifyAssistantRequest,
7 },
8 Client, RequestOptions,
9};
10
11pub struct Assistants<'c, C: Config> {
15 client: &'c Client<C>,
16 pub(crate) request_options: RequestOptions,
17}
18
19impl<'c, C: Config> Assistants<'c, C> {
20 pub fn new(client: &'c Client<C>) -> Self {
21 Self {
22 client,
23 request_options: RequestOptions::new(),
24 }
25 }
26
27 #[crate::byot(T0 = serde::Serialize, R = serde::de::DeserializeOwned)]
29 pub async fn create(
30 &self,
31 request: CreateAssistantRequest,
32 ) -> Result<AssistantObject, OpenAIError> {
33 self.client
34 .post("/assistants", request, &self.request_options)
35 .await
36 }
37
38 #[crate::byot(T0 = std::fmt::Display, R = serde::de::DeserializeOwned)]
40 pub async fn retrieve(&self, assistant_id: &str) -> Result<AssistantObject, OpenAIError> {
41 self.client
42 .get(
43 &format!("/assistants/{assistant_id}"),
44 &self.request_options,
45 )
46 .await
47 }
48
49 #[crate::byot(T0 = std::fmt::Display, T1 = serde::Serialize, R = serde::de::DeserializeOwned)]
51 pub async fn update(
52 &self,
53 assistant_id: &str,
54 request: ModifyAssistantRequest,
55 ) -> Result<AssistantObject, OpenAIError> {
56 self.client
57 .post(
58 &format!("/assistants/{assistant_id}"),
59 request,
60 &self.request_options,
61 )
62 .await
63 }
64
65 #[crate::byot(T0 = std::fmt::Display, R = serde::de::DeserializeOwned)]
67 pub async fn delete(&self, assistant_id: &str) -> Result<DeleteAssistantResponse, OpenAIError> {
68 self.client
69 .delete(
70 &format!("/assistants/{assistant_id}"),
71 &self.request_options,
72 )
73 .await
74 }
75
76 #[crate::byot(R = serde::de::DeserializeOwned)]
78 pub async fn list(&self) -> Result<ListAssistantsResponse, OpenAIError> {
79 self.client.get("/assistants", &self.request_options).await
80 }
81}