use llm_connector::LlmClient;
use serde::{Deserialize, Serialize};
use std::fs;
#[derive(Debug, Deserialize, Serialize)]
struct ProviderConfig {
protocol: String,
api_key: String,
base_url: String,
models: Vec<String>,
#[serde(skip_serializing_if = "Option::is_none")]
note: Option<String>,
}
#[derive(Debug, Deserialize)]
struct KeysConfig {
providers: std::collections::HashMap<String, ProviderConfig>,
}
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
println!("đ Testing Online Model Fetching\n");
let keys_content = fs::read_to_string("keys.yaml")?;
let config: KeysConfig = serde_yaml::from_str(&keys_content)
.map_err(|e| format!("Failed to parse keys.yaml: {}", e))?;
println!("đ Testing fetch_models() for OpenAI protocol providers\n");
let openai_providers: Vec<_> = config
.providers
.iter()
.filter(|(_, cfg)| cfg.protocol == "openai")
.collect();
for (name, provider_config) in openai_providers {
println!("ââââââââââââââââââââââââââââââââââââââââ");
println!("Provider: {}", name);
println!("Base URL: {}", provider_config.base_url);
let client = LlmClient::openai_compatible(
&provider_config.api_key,
&provider_config.base_url,
);
println!("\nđĻ Static supported_models():");
let static_models = client.supported_models();
println!(" Result: {:?}", static_models);
if static_models.is_empty() {
println!(" â
Returns empty (as expected)");
}
println!("\nđ Online fetch_models():");
match client.fetch_models().await {
Ok(models) => {
println!(" â
Success! Found {} models", models.len());
if models.len() <= 10 {
println!(" Models: {:?}", models);
} else {
println!(" First 10 models: {:?}", &models[..10]);
println!(" ... and {} more", models.len() - 10);
}
}
Err(e) => {
println!(" â Error: {}", e);
}
}
println!();
}
if let Some((name, provider_config)) = config.providers.iter().find(|(_, cfg)| cfg.protocol == "aliyun") {
println!("ââââââââââââââââââââââââââââââââââââââââ");
println!("Provider: {} (Aliyun Protocol)", name);
println!("Base URL: {}", provider_config.base_url);
let client = LlmClient::aliyun(&provider_config.api_key);
println!("\nđĻ Static supported_models():");
let static_models = client.supported_models();
println!(" Result: {:?}", static_models);
println!("\nđ Online fetch_models():");
match client.fetch_models().await {
Ok(models) => {
println!(" â
Success! Found {} models", models.len());
println!(" Models: {:?}", models);
}
Err(e) => {
println!(" âšī¸ Error (expected for Aliyun): {}", e);
}
}
println!();
}
println!("ââââââââââââââââââââââââââââââââââââââââ");
println!("Provider: Anthropic (test)");
let anthropic_client = LlmClient::anthropic("test-key");
println!("\nđĻ Static supported_models():");
let static_models = anthropic_client.supported_models();
println!(" Result: {:?}", static_models);
println!("\nđ Online fetch_models():");
match anthropic_client.fetch_models().await {
Ok(models) => {
println!(" â
Success! Found {} models", models.len());
println!(" Models: {:?}", models);
}
Err(e) => {
println!(" âšī¸ Error (expected for Anthropic): {}", e);
}
}
println!("\nââââââââââââââââââââââââââââââââââââââââ");
println!("⨠Testing complete!");
println!("\nđ Summary:");
println!(" - supported_models() returns static/cached models (empty for OpenAI)");
println!(" - fetch_models() retrieves models online from the API");
println!(" - OpenAI protocol supports model listing via /v1/models endpoint");
println!(" - Other protocols may not support model listing");
Ok(())
}