Skip to content

Commit

Permalink
feat: Support for Microsoft azure endpoints (#67)
Browse files Browse the repository at this point in the history
* initial implementation to support Azure Endpoints

* update existing tests

* update lib.rs example

* use doc suggestion

* documentation

* test fix

* test update: remove deprecated codex example; run all tests using 'cargo make all'

* add example for azure openai service

* update example

* update example

* back to Client::new

* updates

* test fix

* update doc
  • Loading branch information
64bit authored Jun 16, 2023
1 parent 77c0b97 commit e0b1543
Show file tree
Hide file tree
Showing 21 changed files with 484 additions and 179 deletions.
7 changes: 3 additions & 4 deletions async-openai/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,13 @@
- [x] Files
- [x] Fine-Tuning (including SSE streaming)
- [x] Images
- [ ] Microsoft Azure Endpoints / AD Authentication (see [issue](https://github.com/64bit/async-openai/issues/32))
- [x] Microsoft Azure Endpoints
- [x] Models
- [x] Moderations
- Non-streaming requests are retried with exponential backoff when [rate limited](https://platform.openai.com/docs/guides/rate-limits) by the API server.
- Ergonomic Rust library with builder pattern for all request objects.

_Being a young project there could be rough edges._

**Note on Azure OpenAI Service**: `async-openai` primarily implements OpenAI APIs, and exposes same library for Azure OpenAI Service too. In reality Azure OpenAI Service provides only subset of OpenAI APIs.
## Usage

The library reads [API key](https://platform.openai.com/account/api-keys) from the environment variable `OPENAI_API_KEY`.
Expand Down Expand Up @@ -104,7 +103,7 @@ async fn main() -> Result<(), Box<dyn Error>> {

Thank you for your time to contribute and improve the project, I'd be happy to have you!

A good starting point would be an [open issue](https://github.com/64bit/async-openai/issues).
A good starting point would be existing [open issues](https://github.com/64bit/async-openai/issues).

## License

Expand Down
9 changes: 5 additions & 4 deletions async-openai/src/audio.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use crate::{
config::Config,
error::OpenAIError,
types::{
CreateTranscriptionRequest, CreateTranscriptionResponse, CreateTranslationRequest,
Expand All @@ -10,12 +11,12 @@ use crate::{

/// Turn audio into text
/// Related guide: [Speech to text](https://platform.openai.com/docs/guides/speech-to-text)
pub struct Audio<'c> {
client: &'c Client,
pub struct Audio<'c, C: Config> {
client: &'c Client<C>,
}

impl<'c> Audio<'c> {
pub fn new(client: &'c Client) -> Self {
impl<'c, C: Config> Audio<'c, C> {
pub fn new(client: &'c Client<C>) -> Self {
Self { client }
}

Expand Down
9 changes: 5 additions & 4 deletions async-openai/src/chat.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use crate::{
config::Config,
error::OpenAIError,
types::{
ChatCompletionResponseStream, CreateChatCompletionRequest, CreateChatCompletionResponse,
Expand All @@ -7,12 +8,12 @@ use crate::{
};

/// Given a chat conversation, the model will return a chat completion response.
pub struct Chat<'c> {
client: &'c Client,
pub struct Chat<'c, C: Config> {
client: &'c Client<C>,
}

impl<'c> Chat<'c> {
pub fn new(client: &'c Client) -> Self {
impl<'c, C: Config> Chat<'c, C> {
pub fn new(client: &'c Client<C>) -> Self {
Self { client }
}

Expand Down
Loading

0 comments on commit e0b1543

Please # to comment.