libopenai

Crates.iolibopenai
lib.rslibopenai
version0.1.0
sourcesrc
created_at2023-03-28 18:04:09.242479
updated_at2023-03-28 18:04:09.242479
descriptionA Rust client for OpenAI's API
homepage
repositoryhttps://github.com/Aandreba/libopenai
max_upload_size
id823296
size185,470
Alex (Aandreba)

documentation

README

GitHub Workflow Status GitHub Crates.io docs.rs

libopenai - Rust client to interact with OpenAI's API

Rust client for OpenAI's API, written with tokio and reqwest

How to use

To add libopenai to your project, you just need to run the following command on your project's main foler:

cargo add libopenai

Example

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(());
}

Features

Cargo features

Currently, the only feature available is tracing, which enables some minor logging

Commit count: 62

cargo fmt