5 unstable releases

new 0.3.2 Sep 12, 2024
0.3.1 Sep 12, 2024
0.3.0 Sep 12, 2024
0.2.0 Sep 12, 2024
0.1.0 Sep 10, 2024

#1364 in Web programming

Download history 390/week @ 2024-09-06

409 downloads per month
Used in mesh

MIT AND Apache-2.0

57KB
1.5K SLoC

OpenAI Rust SDK

Crates.io MIT licensed APACHE-2.0 licensed Build Status

This is an unofficial Rust SDK for the OpenAI API.

More information about this crate can be found in the crate documentation.

Installation

Add opai as a dependency to your Cargo.toml

$ cargo add opai

Usage

An example to create a completion.

use opai::{
    chats::message::{CreateChatCompletion, Message, Role},
    client::Client,
    config::Config,
    models::{gpt::Gpt, Model},
};

#[tokio::main]
async fn main() {
    let config = Config::from_env().unwrap();
    let client = Client::new(config).unwrap();

    let messages: Vec<Message> = vec![Message {
        content: "Hello World".into(),
        role: Role::User,
        name: None,
    }];
    let request = CreateChatCompletion::new(Model::Gpt(Gpt::GPT4), messages);
    let completion = client.chat.create_completion(request).await.unwrap();
    println!("{:?}", completion);
}

License

This project is licensed under the MIT license and Apache-2.0 license.

Dependencies

~6–17MB
~248K SLoC