fieri
Note: fieri's master branch might contain breaking changes. For the most recently released code, look to the latest tag.
Overview
Unofficial Rust client for the OpenAI's API.
fieri provides an asynchronous Rust interface for interacting with the OpenAI API, allowing you to easily use OpenAI's state-of-the-art machine learning models in your Rust projects.
Prerequisites
Before you can use the Rust Client for OpenAI, you'll need to sign up for an API key at the OpenAI Developer Portal. Once you've signed up, you'll be able to find your API key in the API Keys section of the developer portal.
Installation
To use the client in your project, add the following to your Cargo.toml
file:
[dependencies]
fieri = "0.2"
Basic Usage
Generate an image based on a prompt and save it locally.
use std::env;
use fieri::{
Client,
image::{ImageSize, GenerateImageParam, generate},
};
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let client = Client::new(env::var("OPENAI_API_KEY")?);
let param = GenerateImageParam::new("A bunch of cats dancing tango on the top of the highest mountain on Mars.")
.size(ImageSize::S1024x1024)
.n(1);
let image = generate(&client, ¶m)
.await?
.save("/tmp/")
.await?;
Ok(())
}
Generate text based on a prompt
use std::env;
use fieri::{
Client, Models,
completion::{create, CompletionParam}
};
#[tokio::main]
async fn main() -> std::result::Result<(), Box<dyn std::error::Error>> {
let client = Client::new(env::var("OPENAI_API_KEY")?);
let param = CompletionParam::new(Models::Ada)
.prompt("Once upon a time")
.max_tokens(500)
.temperature(0.9)
.top_p(1.0)
.frequency_penalty(0.0)
.presence_penalty(0.0);
let resp = create(&client, ¶m).await?;
if let Some(text) = resp.choices() {
println!("Answer: {}", text[0].text());
}
Ok(())
}
More examples can be found in the docs and the examples directory.
Documentation
fieri Documentation
The official OpenAI documentation
Limitations
Note that the Rust Client for OpenAI is provided as-is, and is not officially supported by OpenAI. While we will do our best to keep the library up-to-date and bug-free, we cannot guarantee that it will always work as expected.
Additionally, the API has usage limits that may affect your ability to use the models. You can view your current usage and limits in the Usage section of your account.
License
fieri is provided under the MIT license. See LICENSE.