Crates.io | async-openai-wasi |
lib.rs | async-openai-wasi |
version | 0.16.4 |
source | src |
created_at | 2023-11-13 02:32:24.089688 |
updated_at | 2023-11-23 12:03:00.026195 |
description | Async bindings for OpenAI REST API based on OpenAPI spec |
homepage | https://github.com/flows-network/async-openai |
repository | https://github.com/flows-network/async-openai |
max_upload_size | |
id | 1033209 |
size | 204,493 |
Async Rust library for OpenAI
async-openai
is an unofficial Rust library for OpenAI.
Note on Azure OpenAI Service (AOS): async-openai
primarily implements OpenAI spec, and doesn't try to maintain parity with spec of AOS.
The library reads API key from the environment variable OPENAI_API_KEY
.
# On macOS/Linux
export OPENAI_API_KEY='sk-...'
# On Windows Powershell
$Env:OPENAI_API_KEY='sk-...'
async-openai
.use async_openai::{
types::{CreateImageRequestArgs, ImageSize, ResponseFormat},
Client,
};
use std::error::Error;
#[tokio::main]
async fn main() -> Result<(), Box<dyn Error>> {
// create client, reads OPENAI_API_KEY environment variable for API key.
let client = Client::new();
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.