Skip to content

Commit

Permalink
feat: support assistants api and fix two markdown links error
Browse files Browse the repository at this point in the history
  • Loading branch information
YanceyOfficial committed Oct 22, 2024
1 parent 7e98344 commit c828f39
Show file tree
Hide file tree
Showing 6 changed files with 434 additions and 2 deletions.
64 changes: 64 additions & 0 deletions rs_openai/src/apis/assistants.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
//! Build assistants that can call models and use tools to perform tasks.
//!
//! [Get started with the Assistants API](https://platform.openai.com/docs/assistants)
use crate::client::OpenAI;
use crate::interfaces::assistants;
use crate::shared::response_wrapper::OpenAIResponse;

pub struct Assistants<'a> {
openai: &'a OpenAI,
}

impl<'a> Assistants<'a> {
pub fn new(openai: &'a OpenAI) -> Self {
Self { openai }
}

/// Create an assistant with a model and instructions.
pub async fn create_assistant(
&self,
req: &assistants::AssistantRequest,
) -> OpenAIResponse<assistants::AssistantResponse> {
self.openai.post("/assistants", req).await
}

/// Returns a list of assistants.
pub async fn list_assistants(
&self,
req: &assistants::ListAssistantRequest,
) -> OpenAIResponse<assistants::ListAssistantResponse> {
self.openai.get("/assistants", req).await
}

/// Retrieves an assistant.
pub async fn retrieve_assistant(
&self,
assistant_id: &str,
) -> OpenAIResponse<assistants::AssistantResponse> {
self.openai
.get(&format!("/assistants/{assistant_id}"), &())
.await
}

/// Modifies an assistant.
pub async fn modify_assistant(
&self,
assistant_id: &str,
req: &assistants::AssistantRequest,
) -> OpenAIResponse<assistants::AssistantResponse> {
self.openai
.post(&format!("/assistants/{assistant_id}"), req)
.await
}

/// Delete an assistant.
pub async fn delete_assistant(
&self,
assistant_id: &str,
) -> OpenAIResponse<assistants::DeleteAssistantResponse> {
self.openai
.delete(&format!("/assistants/{assistant_id}"), &())
.await
}
}
1 change: 1 addition & 0 deletions rs_openai/src/apis/mod.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
pub mod assistants;
pub mod audio;
pub mod batch;
pub mod chat;
Expand Down
Loading

0 comments on commit c828f39

Please sign in to comment.