-
Notifications
You must be signed in to change notification settings - Fork 145
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* make speech example work * response save api for speech * create_all dir * update image types and examples * cleanup * chat completion request response * completions types * all types of chat completion message types * fix function call examples * bunch of from trait impls * updates to file and fine tune job types * Assistants API group * thread and message types * run object * messages and threads * thread runs * more thread and runs * error fix * run steps * assitant files * message files * update docs * updates * docs * cleanup * updated spec * latest spec * fixes * assistants example * fix * updated example * cargo fix * cargo fmt
- Loading branch information
Showing
41 changed files
with
9,016 additions
and
2,053 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,3 +5,5 @@ Cargo.lock | |
|
||
# directory used to store images | ||
data | ||
|
||
*.mp3 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
use serde::Serialize; | ||
|
||
use crate::{ | ||
config::Config, | ||
error::OpenAIError, | ||
types::{ | ||
AssistantFileObject, CreateAssistantFileRequest, DeleteAssistantFileResponse, | ||
ListAssistantFilesResponse, | ||
}, | ||
Client, | ||
}; | ||
|
||
/// Files attached to an assistant. | ||
pub struct AssistantFiles<'c, C: Config> { | ||
client: &'c Client<C>, | ||
pub assistant_id: String, | ||
} | ||
|
||
impl<'c, C: Config> AssistantFiles<'c, C> { | ||
pub fn new(client: &'c Client<C>, assistant_id: &str) -> Self { | ||
Self { | ||
client, | ||
assistant_id: assistant_id.into(), | ||
} | ||
} | ||
|
||
/// Create an assistant file by attaching a [File](https://platform.openai.com/docs/api-reference/files) to an [assistant](https://platform.openai.com/docs/api-reference/assistants). | ||
pub async fn create( | ||
&self, | ||
request: CreateAssistantFileRequest, | ||
) -> Result<AssistantFileObject, OpenAIError> { | ||
self.client | ||
.post(&format!("/assistants/{}/files", self.assistant_id), request) | ||
.await | ||
} | ||
|
||
/// Retrieves an AssistantFile. | ||
pub async fn retrieve(&self, file_id: &str) -> Result<AssistantFileObject, OpenAIError> { | ||
self.client | ||
.get(&format!( | ||
"/assistants/{}/files/{file_id}", | ||
self.assistant_id | ||
)) | ||
.await | ||
} | ||
|
||
/// Delete an assistant file. | ||
pub async fn delete(&self, file_id: &str) -> Result<DeleteAssistantFileResponse, OpenAIError> { | ||
self.client | ||
.delete(&format!( | ||
"/assistants/{}/files/{file_id}", | ||
self.assistant_id | ||
)) | ||
.await | ||
} | ||
|
||
/// Returns a list of assistant files. | ||
pub async fn list<Q>(&self, query: &Q) -> Result<ListAssistantFilesResponse, OpenAIError> | ||
where | ||
Q: Serialize + ?Sized, | ||
{ | ||
self.client | ||
.get_with_query(&format!("/assistants/{}/files", self.assistant_id), query) | ||
.await | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
use serde::Serialize; | ||
|
||
use crate::{ | ||
config::Config, | ||
error::OpenAIError, | ||
types::{ | ||
AssistantObject, CreateAssistantRequest, DeleteAssistantResponse, ListAssistantsResponse, | ||
ModifyAssistantRequest, | ||
}, | ||
AssistantFiles, Client, | ||
}; | ||
|
||
/// Build assistants that can call models and use tools to perform tasks. | ||
/// | ||
/// [Get started with the Assistants API](https://platform.openai.com/docs/assistants) | ||
pub struct Assistants<'c, C: Config> { | ||
client: &'c Client<C>, | ||
} | ||
|
||
impl<'c, C: Config> Assistants<'c, C> { | ||
pub fn new(client: &'c Client<C>) -> Self { | ||
Self { client } | ||
} | ||
|
||
/// Assistant [AssistantFiles] API group | ||
pub fn files(&self, assistant_id: &str) -> AssistantFiles<C> { | ||
AssistantFiles::new(self.client, assistant_id) | ||
} | ||
|
||
/// Create an assistant with a model and instructions. | ||
pub async fn create( | ||
&self, | ||
request: CreateAssistantRequest, | ||
) -> Result<AssistantObject, OpenAIError> { | ||
self.client.post("/assistants", request).await | ||
} | ||
|
||
/// Retrieves an assistant. | ||
pub async fn retrieve(&self, assistant_id: &str) -> Result<AssistantObject, OpenAIError> { | ||
self.client | ||
.get(&format!("/assistants/{assistant_id}")) | ||
.await | ||
} | ||
|
||
/// Modifies an assistant. | ||
pub async fn update( | ||
&self, | ||
assistant_id: &str, | ||
request: ModifyAssistantRequest, | ||
) -> Result<AssistantObject, OpenAIError> { | ||
self.client | ||
.post(&format!("/assistants/{assistant_id}"), request) | ||
.await | ||
} | ||
|
||
/// Delete an assistant. | ||
pub async fn delete(&self, assistant_id: &str) -> Result<DeleteAssistantResponse, OpenAIError> { | ||
self.client | ||
.delete(&format!("/assistants/{assistant_id}")) | ||
.await | ||
} | ||
|
||
/// Returns a list of assistants. | ||
pub async fn list<Q>(&self, query: &Q) -> Result<ListAssistantsResponse, OpenAIError> | ||
where | ||
Q: Serialize + ?Sized, | ||
{ | ||
self.client.get_with_query("/assistants", query).await | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.