Expand description
§Models Module
This module provides functionality for interacting with the OpenAI Models API. It allows you to list, retrieve, and delete models available in the OpenAI platform.
§Key Features
- List Models: Retrieve all available models in your organization
- Retrieve Model: Get detailed information about a specific model
- Delete Model: Remove fine-tuned models that you own
§Quick Start
use openai_tools::models::request::Models;
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
// Create a Models client
let models = Models::new()?;
// List all available models
let response = models.list().await?;
println!("Found {} models", response.data.len());
Ok(())
}§Usage Examples
§List All Models
use openai_tools::models::request::Models;
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let models = Models::new()?;
let response = models.list().await?;
for model in &response.data {
println!("{}: owned by {}", model.id, model.owned_by);
}
Ok(())
}§Retrieve a Specific Model
use openai_tools::models::request::Models;
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let models = Models::new()?;
// Get details of gpt-4o-mini
let model = models.retrieve("gpt-4o-mini").await?;
println!("Model: {}", model.id);
println!("Owned by: {}", model.owned_by);
println!("Created: {}", model.created);
Ok(())
}§Delete a Fine-tuned Model
use openai_tools::models::request::Models;
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let models = Models::new()?;
// Delete a fine-tuned model (must be owned by you)
let result = models.delete("ft:gpt-4o-mini:my-org:my-suffix:id").await?;
if result.deleted {
println!("Successfully deleted: {}", result.id);
}
Ok(())
}§Response Structure
§Model Object
Each model object contains:
id: Model identifier (e.g., “gpt-4o-mini”)object: Always “model”created: Unix timestamp of creationowned_by: Organization that owns the model
§Delete Response
When deleting a model:
id: The deleted model’s IDobject: Always “model”deleted: Boolean indicating success