11 个版本 (4 个重大更新)

0.5.0 2023 年 2 月 1 日
0.4.0 2023 年 1 月 27 日
0.3.3 2023 年 1 月 22 日
0.2.0 2023 年 1 月 22 日
0.1.3 2023 年 1 月 22 日

#16#gpt-3

Download history 10/week @ 2024-03-09 1/week @ 2024-03-16 31/week @ 2024-03-30 4/week @ 2024-04-06

63 每月下载次数
openai-chat 中使用

MIT 许可证

14KB
294

关于

为 Rust 提供的 OpenAI API 客户端

有关 OpenAI API 的更多信息: https://beta.openai.com/docs/

用法

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


}

依赖项

~20–35MB
~666K SLoC