7 releases
0.3.4 | Jun 26, 2022 |
---|---|
0.3.3 | Jun 26, 2022 |
0.3.2 | May 24, 2022 |
0.2.0 | May 13, 2022 |
0.1.0 | May 10, 2022 |
#3 in #gpt3
70KB
1K
SLoC
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}");
}
Dependencies
~4–16MB
~246K SLoC