Crate libopenai

source ·
Expand description

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

Modules

  • Learn how to turn audio into text.
  • Given a chat conversation, the model will return a chat completion response.
  • Structures and methods commonly used throughout the library
  • Given a prompt, the model will return one or more predicted completions, and can also return the probabilities of alternative tokens at each position.
  • Given a prompt and an instruction, the model will return an edited version of the prompt.
  • Get a vector representation of a given input that can be easily consumed by machine learning models and algorithms.
  • Library’s error types
  • Files are used to upload documents that can be used with features like fine-tuning.
  • Manage fine-tuning jobs to tailor a model to your specific training data.
  • Given a prompt and/or an input image, the model will generate a new image.
  • List and describe the various models available in the API.
  • Given a input text, outputs if the model classifies it as violating OpenAI’s content policy.

Structs