#openai-api #openai #ai #ChatGPT

libopenai

OpenAI API的Rust客户端

1 个不稳定版本

0.1.0 2023年3月28日

#683 in 图像

自定义许可

130KB
3K SLoC

GitHub Workflow Status GitHub Crates.io docs.rs

libopenai - 与OpenAI API交互的Rust客户端

使用tokio和reqwest编写的OpenAI API的Rust客户端

如何使用

要将libopenai添加到您的项目,只需在项目主目录下运行以下命令

cargo add libopenai

示例

use libopenai::prelude::*;

#[tokio::main]
async fn main() -> Result<()> {
    // OPTIONAL: Load variables in a `.env` file into the enviroment
    dotenv::dotenv().unwrap();

    let client = Client::new(
        None, // Gets api key from `OPENAI_API_KEY` enviroment variable
        None, // No organization specified
    )?;

    // Send basic completion request
    let basic = Completion::new(
        "text-davinci-003",
        "Whats the best way to calculate a factorial?",
        &client,
    )
    .await?;

    // Print the result
    println!("{:#?}", basic);
    return Ok(());
}

功能

Cargo功能

目前,唯一可用的功能是 跟踪,它启用了少量日志记录

依赖项

~15–31MB
~471K SLoC