Module models

Source
Expand description

This module provides functionality for interacting with the OpenAI Models API.

The Models API allows you to retrieve a list of available models and fetch details about a specific model. These endpoints are useful for determining which model IDs you can use for completions, chat, embeddings, and other functionalities.

§Usage

use chat_gpt_lib_rs::api_resources::models;
use chat_gpt_lib_rs::{OpenAIClient, OpenAIError};

#[tokio::main]
async fn main() -> Result<(), OpenAIError> {
    let client = OpenAIClient::new(None)?;

    // List all available models.
    let all_models = models::list_models(&client).await?;
    println!("Available Models: {:?}", all_models);

    // Retrieve a specific model by ID.
    if let Some(first_model) = all_models.first() {
        let model_id = &first_model.id;
        let retrieved = models::retrieve_model(&client, model_id).await?;
        println!("Retrieved Model: {:?}", retrieved);
    }

    Ok(())
}

Structs§

ModelInfo
Represents an OpenAI model (detailed info from API).
ModelPermission
Describes permissions for a model.

Enums§

Model
An enum representing known OpenAI model identifiers, plus an Other variant for unrecognized or custom model IDs.

Functions§

list_models
Retrieves a list of all available models from the OpenAI API.
retrieve_model
Retrieves the details for a specific model by its model_id.