OpenAI Dive

OpenAI Dive is a Rust API client that allows you to interact with the OpenAI API.

ini [dependencies] openai_dive = "0.1.0"

Endpoints

List models

Lists the currently available models, and provides basic information about each one such as the owner and availability.

URL https://api.openai.com/v1/models

Method GET

```rs use openai_rs::v1::api::Client;

[tokio::main]

async fn main() -> Result<()> { let apikey = "YOUR API KEY".tostring();

let client = Client::new(api_key);

let result = client.models().list().await.unwrap();

println!("{:?}", result);

} ```

More information: List models

Retrieve model

Retrieves a model instance, providing basic information about the model such as the owner and permissioning.

URL https://api.openai.com/v1/models/{model}

Method GET

```rs use openairs::v1::api::Client; use openairs::v1::models::OpenAIModel;

[tokio::main]

async fn main() -> Result<()> { let apikey = "YOUR API KEY".tostring();

let model_id = OpenAIModel::TextDavinci003.to_string(); // text-davinci-003

let client = Client::new(api_key);

let result = client.models().get(model_id).await.unwrap();

println!("{:?}", result);

} ```

More information: Retrieve models

Create completion

Creates a completion for the provided prompt and parameters.

URL https://api.openai.com/v1/completions

Method POST

```rs use openairs::v1::api::Client; use openairs::v1::resources::completion::CompletionParameters; use openai_rs::v1::models::OpenAIModel;

[tokio::main]

async fn main() -> Result<()> { let apikey = "YOUR API KEY".tostring();

let parameters = CompletionParameters {
    model: OpenAIModel::TextDavinci003.to_string(), // text-davinci-003
    prompt: "Say this is a test".to_string(),
    max_tokens: 10,
    temperature: None,
    suffix: None,
};

let client = Client::new(api_key);

let result = client.completions().create(parameters).await.unwrap();

println!("{:?}", result);

} ```

More information: Create completion

Create chat completion

Creates a completion for the chat message.

URL https://api.openai.com/v1/chat/completions

Method POST

```rs use openairs::v1::api::Client; use openairs::v1::resources::chatcompletion::{ChatCompletionParameters, ChatMessage}; use openairs::v1::models::OpenAIModel;

[tokio::main]

async fn main() -> Result<()> { let apikey = "YOUR API KEY".tostring();

let parameters = ChatCompletionParameters {
    model: OpenAIModel::Chat3X5Turbo0301.to_string(), // gpt-3.5-turbo-0301
    messages: vec![
        ChatMessage {
            role: "user".to_string(),
            content: "Hello!".to_string(),
        },
    ],
    max_tokens: 12,
    temperature: None,
};

let client = Client::new(api_key);

let result = client.chat().create(parameters).await.unwrap();

println!("{:?}", result);

} ```

More information: Create chat completion

Create edit

Creates a new edit for the provided input, instruction, and parameters.

URL https://api.openai.com/v1/edits

Method POST

```rs use openairs::v1::api::Client; use openairs::v1::resources::edit::EditParameters; use openai_rs::v1::models::OpenAIModel;

[tokio::main]

async fn main() -> Result<()> { let apikey = "YOUR API KEY".tostring();

let parameters = EditParameters {
    model: OpenAIModel::TextDavinciEdit001.to_string(), // text-davinci-edit-001
    input: "What day of the wek is it?".to_string(),
    instruction: "Fix the spelling mistakes".to_string(),
    temperature: None,
};

let client = Client::new(api_key);

let result = client.edits().create(parameters).await.unwrap();

println!("{:?}", result);

} ```

More information: Create edit