gpt-rs

Crates.iogpt-rs
lib.rsgpt-rs
version0.1.1
sourcesrc
created_at2023-07-26 10:54:30.524747
updated_at2023-07-26 11:08:35.231495
descriptionThis crate provides a simple way to interact with the OpenAI API
homepagehttps://github.com/Kobayashi-takumi/gpt-rs
repositoryhttps://github.com/Kobayashi-takumi/gpt-rs
max_upload_size
id926357
size21,376
(Kobayashi-takumi)

documentation

README

gpt

This crate provides a simple way to interact with the OpenAI API from Rust.

Example

This asynchronous example uses Tokio and enables some optional features, so your Cargo.toml could look like this:

[dependencies]
gpt = { git="https://github.com/Kobayashi-takumi/gpt-rs" }
tokio = { version = "1", features = ["full"] }

And then the code:

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    let client = Client::new(Config {
        api_key:"<Your API_KEY>".to_string(),
        organization: Some("<Your ORGANIZATION>"),
    })?;
    let res = Chat::builder()
        .config(Default::default())
        .request(vec!["hi".into()])
        .build()?
        .execute(&client)
        .await?;
}

Create chat completion

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    let client = Client::new(Config {
        api_key:"<Your API_KEY>".to_string(),
        organization: Some("<Your ORGANIZATION>".to_string()),
    })?;
    let res = Chat::builder()
        .config(Default::default())
        .request(vec!["hi".into()])
        .build()?
        .execute(&client)
        .await?;
    Ok(())
}

Create image

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    let client = Client::new(Config {
        api_key:"<Your API_KEY>".to_string(),
        organization: Some("<Your ORGANIZATION>"),
    })?;
    let res = CreateImage::builder()
        .request("doc".into())
        .build()?
        .execute(&client)
        .await;
    Ok(())
}
Commit count: 10

cargo fmt