gpt3_rs

Crates.iogpt3_rs
lib.rsgpt3_rs
version0.3.4
sourcesrc
created_at2022-05-10 16:55:46.455855
updated_at2022-06-26 10:08:31.776005
descriptionAn API wrapper for OpenAi's gpt-3
homepage
repositoryhttps://github.com/Sleepy-Kitten/gpt3_rs
max_upload_size
id584086
size70,817
(sleepy-kitten)

documentation

README

gpt3_rs

gpt3_rs is a rust library for interacting with OpenAi's gpt3

features

  • builder pattern to build request structs
  • easy to use
  • supports async and blocking

Examples

use gpt3_rs::{Client, api::*, Model};

#[tokio::main]
async fn main() {
    let token = std::env::var("GPT_API_TOKEN").unwrap();
    let client = Client::new(token);

    let request = completions::Builder::default()
        .model(Model::Babbage)
        .prompt("what is 1 + 2?")
        .build()
        .unwrap();
    let response = request.request(&client).await.unwrap();
    let answer = &response.choices[0].text;

    println!("{answer}");
}
use gpt3_rs::{Client, api::*, Model};

#[tokio::main]
async fn main() {
    let token = std::env::var("GPT_API_TOKEN").unwrap();
    let client = Client::new(token);

    let request = classification::Builder::default()
        .model(Model::Curie)
        .search_model(Model::Ada)
        .query("It is a rainy day :(")
        .examples(&[
            &["A happy moment", "Positive"],
            &["I am sad.", "Negative"],
            &["I am feeling awesome", "Positive"]
        ])
        .labels(&["Positive", "Negative", "Neutral"])
        .build()
        .unwrap();

    let response = request.request(&client).await.unwrap();
    let answer = &response.choices[0].text;

    println!("{answer}");
}
Commit count: 87

cargo fmt