Crates.io | flynn-openai |
lib.rs | flynn-openai |
version | 0.26.0 |
source | src |
created_at | 2024-11-10 15:02:46.524545 |
updated_at | 2024-11-10 15:44:19.647716 |
description | Rust library for OpenAI |
homepage | https://github.com/wufly632/flynn-openai |
repository | https://github.com/wufly632/flynn-openai |
max_upload_size | |
id | 1442977 |
size | 357,773 |
Async Rust library for OpenAI
flynn-openai
is an unofficial Rust library for OpenAI.
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-...'
flynn-openai
.Only types for Realtime API are implemented, and can be enabled with feature flag realtime
These types may change when OpenAI releases official specs for them.
use flynn_openai::{
types::{CreateImageRequestArgs, ImageSize, ImageResponseFormat},
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(ImageResponseFormat::Url)
.size(ImageSize::S256x256)
.user("flynn-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 taking the time to contribute and improve the project. I'd be happy to have you!
All forms of contributions, such as new features requests, bug fixes, issues, documentation, testing, comments, examples etc. are welcome.
A good starting point would be to look at existing open issues.
To maintain quality of the project, a minimum of the following is a must for code contribution:
This project adheres to Rust Code of Conduct
This project is licensed under MIT license.