Async Rust library for OpenAI
async-openai
is an unofficial Rust library for OpenAI REST API.
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.
The library reads API key from the environment variable OPENAI_API_KEY
.
```bash
export OPENAIAPIKEY='sk-...' ```
```powershell
$Env:OPENAIAPIKEY='sk-...' ```
async-openai
.```rust use async_openai::{ types::{CreateImageRequestArgs, ImageSize, ResponseFormat}, Client, }; use std::error::Error;
async fn main() -> Result<(), Box
let request = CreateImageRequestArgs::default()
.prompt("cats on sofa and carpet in living room")
.n(2)
.response_format(ResponseFormat::Url)
.size(ImageSize::S256x256)
.user("async-openai")
.build()?;
let response = client.images().create(request).await?;
// Download and save images to ./data directory.
// Each url is downloaded and saved in dedicated Tokio task.
// Directory is created if it doesn't exist.
let paths = response.save("./data").await?;
paths
.iter()
.for_each(|path| println!("Image file path: {}", path.display()));
Ok(())
} ```
Thank you for your time to contribute and improve the project, I'd be happy to have you!
A good starting point would be existing open issues.
This project is licensed under MIT license.