Crates.io | libopenai |
lib.rs | libopenai |
version | 0.1.0 |
source | src |
created_at | 2023-03-28 18:04:09.242479 |
updated_at | 2023-03-28 18:04:09.242479 |
description | A Rust client for OpenAI's API |
homepage | |
repository | https://github.com/Aandreba/libopenai |
max_upload_size | |
id | 823296 |
size | 185,470 |
Rust client for OpenAI's API, written with tokio and reqwest
To add libopenai
to your project, you just need to run the following command on your project's main foler:
cargo add libopenai
use libopenai::prelude::*;
#[tokio::main]
async fn main() -> Result<()> {
// OPTIONAL: Load variables in a `.env` file into the enviroment
dotenv::dotenv().unwrap();
let client = Client::new(
None, // Gets api key from `OPENAI_API_KEY` enviroment variable
None, // No organization specified
)?;
// Send basic completion request
let basic = Completion::new(
"text-davinci-003",
"Whats the best way to calculate a factorial?",
&client,
)
.await?;
// Print the result
println!("{:#?}", basic);
return Ok(());
}
Currently, the only feature available is tracing, which enables some minor logging