async_openai_alt/
assistants.rs1use serde::Serialize;
2
3use crate::{
4 config::Config,
5 error::OpenAIError,
6 types::{
7 AssistantObject, CreateAssistantRequest, DeleteAssistantResponse, ListAssistantsResponse,
8 ModifyAssistantRequest,
9 },
10 AssistantFiles, Client,
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 pub fn files(&self, assistant_id: &str) -> AssistantFiles<C> {
27 AssistantFiles::new(self.client, assistant_id)
28 }
29
30 pub async fn create(
32 &self,
33 request: CreateAssistantRequest,
34 ) -> Result<AssistantObject, OpenAIError> {
35 self.client.post("/assistants", request).await
36 }
37
38 pub async fn retrieve(&self, assistant_id: &str) -> Result<AssistantObject, OpenAIError> {
40 self.client
41 .get(&format!("/assistants/{assistant_id}"))
42 .await
43 }
44
45 pub async fn update(
47 &self,
48 assistant_id: &str,
49 request: ModifyAssistantRequest,
50 ) -> Result<AssistantObject, OpenAIError> {
51 self.client
52 .post(&format!("/assistants/{assistant_id}"), request)
53 .await
54 }
55
56 pub async fn delete(&self, assistant_id: &str) -> Result<DeleteAssistantResponse, OpenAIError> {
58 self.client
59 .delete(&format!("/assistants/{assistant_id}"))
60 .await
61 }
62
63 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}