feat(config): 为 anthropic、kimi、deepseek 添加 list_models 支持
This commit is contained in:
@@ -830,14 +830,14 @@ impl ConfigCommand {
|
||||
async fn list_models(&self) -> Result<()> {
|
||||
let manager = ConfigManager::new()?;
|
||||
let config = manager.config();
|
||||
|
||||
|
||||
match config.llm.provider.as_str() {
|
||||
"ollama" => {
|
||||
let client = crate::llm::OllamaClient::new(
|
||||
&config.llm.ollama.url,
|
||||
&config.llm.ollama.model,
|
||||
);
|
||||
|
||||
|
||||
println!("Fetching available models from Ollama...");
|
||||
match client.list_models().await {
|
||||
Ok(models) => {
|
||||
@@ -859,7 +859,7 @@ impl ConfigCommand {
|
||||
key,
|
||||
&config.llm.openai.model,
|
||||
)?;
|
||||
|
||||
|
||||
println!("Fetching available models from OpenAI...");
|
||||
match client.list_models().await {
|
||||
Ok(models) => {
|
||||
@@ -877,11 +877,110 @@ impl ConfigCommand {
|
||||
bail!("OpenAI API key not configured");
|
||||
}
|
||||
}
|
||||
"anthropic" => {
|
||||
if let Some(ref key) = config.llm.anthropic.api_key {
|
||||
let client = crate::llm::AnthropicClient::new(
|
||||
key,
|
||||
&config.llm.anthropic.model,
|
||||
)?;
|
||||
|
||||
println!("Fetching available models from Anthropic...");
|
||||
match client.list_models().await {
|
||||
Ok(models) => {
|
||||
println!("\n{}", "Available models:".bold());
|
||||
for model in models {
|
||||
let marker = if model == config.llm.anthropic.model { "●".green() } else { "○".dimmed() };
|
||||
println!("{} {}", marker, model);
|
||||
}
|
||||
}
|
||||
Err(e) => {
|
||||
println!("{} Failed to fetch models: {}", "✗".red(), e);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
bail!("Anthropic API key not configured");
|
||||
}
|
||||
}
|
||||
"kimi" => {
|
||||
if let Some(ref key) = config.llm.kimi.api_key {
|
||||
let client = crate::llm::KimiClient::with_base_url(
|
||||
key,
|
||||
&config.llm.kimi.model,
|
||||
&config.llm.kimi.base_url,
|
||||
)?;
|
||||
|
||||
println!("Fetching available models from Kimi...");
|
||||
match client.list_models().await {
|
||||
Ok(models) => {
|
||||
println!("\n{}", "Available models:".bold());
|
||||
for model in models {
|
||||
let marker = if model == config.llm.kimi.model { "●".green() } else { "○".dimmed() };
|
||||
println!("{} {}", marker, model);
|
||||
}
|
||||
}
|
||||
Err(e) => {
|
||||
println!("{} Failed to fetch models: {}", "✗".red(), e);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
bail!("Kimi API key not configured");
|
||||
}
|
||||
}
|
||||
"deepseek" => {
|
||||
if let Some(ref key) = config.llm.deepseek.api_key {
|
||||
let client = crate::llm::DeepSeekClient::with_base_url(
|
||||
key,
|
||||
&config.llm.deepseek.model,
|
||||
&config.llm.deepseek.base_url,
|
||||
)?;
|
||||
|
||||
println!("Fetching available models from DeepSeek...");
|
||||
match client.list_models().await {
|
||||
Ok(models) => {
|
||||
println!("\n{}", "Available models:".bold());
|
||||
for model in models {
|
||||
let marker = if model == config.llm.deepseek.model { "●".green() } else { "○".dimmed() };
|
||||
println!("{} {}", marker, model);
|
||||
}
|
||||
}
|
||||
Err(e) => {
|
||||
println!("{} Failed to fetch models: {}", "✗".red(), e);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
bail!("DeepSeek API key not configured");
|
||||
}
|
||||
}
|
||||
"openrouter" => {
|
||||
if let Some(ref key) = config.llm.openrouter.api_key {
|
||||
let client = crate::llm::OpenRouterClient::with_base_url(
|
||||
key,
|
||||
&config.llm.openrouter.model,
|
||||
&config.llm.openrouter.base_url,
|
||||
)?;
|
||||
|
||||
println!("Fetching available models from OpenRouter...");
|
||||
match client.list_models().await {
|
||||
Ok(models) => {
|
||||
println!("\n{}", "Available models:".bold());
|
||||
for model in models {
|
||||
let marker = if model == config.llm.openrouter.model { "●".green() } else { "○".dimmed() };
|
||||
println!("{} {}", marker, model);
|
||||
}
|
||||
}
|
||||
Err(e) => {
|
||||
println!("{} Failed to fetch models: {}", "✗".red(), e);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
bail!("OpenRouter API key not configured");
|
||||
}
|
||||
}
|
||||
provider => {
|
||||
println!("Listing models not supported for provider: {}", provider);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user