Crates.io | openai_api_client |
lib.rs | openai_api_client |
version | 0.5.0 |
source | src |
created_at | 2023-01-21 17:59:12.269783 |
updated_at | 2023-02-01 07:27:34.743019 |
description | OpenAI API client for Rust |
homepage | |
repository | https://github.com/evgenyigumnov/openai_api_client |
max_upload_size | |
id | 764510 |
size | 15,146 |
OpenAI API client for Rust
More information about the OpenAI API: https://beta.openai.com/docs/
use openai_api_client::*;
#[actix_rt::main]
async fn main() {
// pretty usage
let api_key = "............";
let model = "text-davinci-003";
let max_tokens:u32 = 3;
let prompt = "Is Biden president of USA? If you ask yes or not. \
I say:";
let result: String = completions_pretty(prompt, model, max_tokens, &api_key).await.unwrap();
println!("result: {}", result);
// hardcore usage
let params = CompletionsParams {
model: model.to_string(),
temperature: 0,
max_tokens: max_tokens,
top_p: 1.0,
frequency_penalty: 0.0,
presence_penalty: 0.0,
stop: None,
suffix: None,
n: 1,
stream: false,
logprobs: None,
echo: false,
best_of: 1,
logit_bias: None,
user: None,
};
let new_promt = "Is Biden president of Canada? If you ask yes or \
not. I say:";
let result_hard = dbg!(completions(new_promt, ¶ms, &api_key).await.unwrap());
println!("result: {}", result_hard.choices[0].text);
}
use openai_api_client::*;
#[actix_rt::main]
async fn main() {
// pretty usage
let api_key = "............";
let result_edits:String = edits_pretty("Helllo, Mick!", "Fix grammar",
"text-davinci-edit-001", &api_key).await.unwrap();
println!("result: {}", result_edits);
}