I’m working on a Rust library for the OpenAI API! It’s features include:
- asynchrony
- high-level functions
- auto-generated enums
- for example,
ModelIDwill generate with all currently available model IDs, no need to worry about waiting for the library to update!
- for example,
- authentication via env var
Here’s an example of what a Rust program using this library looks like:
use openai::{
completions::{ Completion, CreateCompletionRequestBody },
models::ModelID,
};
use dotenvy::dotenv;
#[tokio::main]
async fn main() {
// Make sure you have a file named `.env` with the `OPENAI_KEY` environment variable defined!
dotenv().unwrap();
let completion = Completion::new(&CreateCompletionRequestBody {
model: ModelID::TextDavinci003,
prompt: “Say this is a test”,
max_tokens: Some(7),
temperature: Some(0),
..Default::default()
}).await.unwrap();
let response = completion.choices.first().unwrap().text;
println!("{response}"); // “This is indeed a test”
}
The library is currently in its alpha stage and not yet complete. If you’d like to contribute or try it out, come look at the GitHub repository!
https://github.com/valentinegb/openai