openai_api_client

Crates.ioopenai_api_client
lib.rsopenai_api_client
version0.5.0
sourcesrc
created_at2023-01-21 17:59:12.269783
updated_at2023-02-01 07:27:34.743019
descriptionOpenAI API client for Rust
homepage
repositoryhttps://github.com/evgenyigumnov/openai_api_client
max_upload_size
id764510
size15,146
Evgeny Igumnov (evgenyigumnov)

documentation

README

About

OpenAI API client for Rust

More information about the OpenAI API: https://beta.openai.com/docs/

Usage

Completions API


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, &params, &api_key).await.unwrap());
    println!("result: {}", result_hard.choices[0].text);

}

Edits API


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);


}

Commit count: 29

cargo fmt