openai-rs-api

Crates.ioopenai-rs-api
lib.rsopenai-rs-api
version1.1.3
sourcesrc
created_at2023-07-03 15:38:18.654606
updated_at2023-07-07 17:42:18.483927
descriptionA Rust wrapper for the OpenAI API
homepage
repository
max_upload_size
id907133
size96,070
Danila Verbinskiy (hikionori)

documentation

https://www.docs.rs/openai-rs-api

README

OpenAI Rust Api

Unofficial api client for OpenAI

Functions of core module

Example of usage core module

Chat completion

use openai_rs_api::core::models::chat::{ChatParameters, ChatResponse, Message};
use openai_rs_api::core::OpenAI;

#[tokio::main]
async fn main() {
    let oai = OpenAI::new("API_KEY".to_string(), "API_ORG".to_string());
    let parameters = ChatParameters::new(
        "gpt-3.5-turbo-16k".to_string(),
        vec![Message {
            role: "user".to_string(),
            content: Some("Hello, my name is".to_string()),
            name: None,
            function_call: None,
        }],
    );
    let response: ChatResponse = oai.create_chat_completions(parameters).await.unwrap();
    // print answer message
    if let Some(content) = &response.choices.get(0).unwrap().message.content {
        println!("{}", content);
    }
}
Commit count: 0

cargo fmt