pub trait ModelListingClient {
// Required method
fn list_models(
&self,
) -> impl Future<Output = Result<ModelList, ModelListingError>> + WasmCompatSend;
}Expand description
A provider client with model listing capabilities.
This trait provides methods to discover and list available models from LLM providers. All models are returned in a single list.
§Type Parameters
ModelLister: The type that implements the actual model listing logic
§Example
ⓘ
use rig::client::ModelListingClient;
use rig::providers::openai::Client;
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
// Initialize the OpenAI client
let openai = Client::new("your-open-ai-api-key");
// List all available models
let models = openai.list_models().await?;
println!("Available models:");
for model in models.iter() {
println!("- {} ({})", model.display_name(), model.id);
}
Ok(())
}Required Methods§
Sourcefn list_models(
&self,
) -> impl Future<Output = Result<ModelList, ModelListingError>> + WasmCompatSend
fn list_models( &self, ) -> impl Future<Output = Result<ModelList, ModelListingError>> + WasmCompatSend
List all available models from the provider.
This method retrieves all available models. Providers that support pagination internally handle fetching all pages and return complete results.
§Returns
A ModelList containing all available models from the provider.
§Errors
Returns a ModelListingError if:
- The request to the provider fails
- Authentication fails
- The provider returns an error response
- The response cannot be parsed
§Example
ⓘ
use rig::client::ModelListingClient;
use rig::providers::openai::Client;
let openai = Client::from_env();
let models = openai.list_models().await?;
println!("Found {} models", models.len());
for model in models.iter() {
println!("- {} ({})", model.display_name(), model.id);
}Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.