Skip to content

Commit a337075

Browse files
committed
refactor(models): remove redundant models_dev_id method
1 parent e38ddbd commit a337075

3 files changed

Lines changed: 12 additions & 15 deletions

File tree

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ rullm --system "You are a helpful assistant." "Summarize this text"
6666
# List available models (shows only chat models, with your aliases)
6767
rullm models list
6868

69-
# Update model list from models.dev (no API keys required)
69+
# Update model list
7070
rullm models update
7171

7272
# Manage aliases

crates/rullm-cli/src/commands/models.rs

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ use chrono::Utc;
33
use clap::{Args, Subcommand};
44
use serde::Deserialize;
55
use std::collections::HashMap;
6+
use std::time::Duration;
67
use strum::IntoEnumIterator;
78

89
use crate::{
@@ -66,7 +67,7 @@ impl ModelsArgs {
6667
}
6768
}
6869
ModelsAction::Update => {
69-
let supported: Vec<&str> = Provider::iter().map(|p| p.models_dev_id()).collect();
70+
let supported: Vec<String> = Provider::iter().map(|p| p.to_string()).collect();
7071

7172
crate::output::progress("Fetching models from models.dev...", output_level);
7273

@@ -240,15 +241,21 @@ struct ModelsDevModel {
240241
id: Option<String>,
241242
}
242243

243-
async fn fetch_models_from_models_dev(supported_providers: &[&str]) -> Result<Vec<String>> {
244-
let response = reqwest::get("https://models.dev/api.json")
244+
async fn fetch_models_from_models_dev(supported_providers: &[String]) -> Result<Vec<String>> {
245+
let client = reqwest::Client::builder()
246+
.timeout(Duration::from_secs(10))
247+
.build()?;
248+
249+
let response = client
250+
.get("https://models.dev/api.json")
251+
.send()
245252
.await?
246253
.error_for_status()?;
247254
let providers: HashMap<String, ModelsDevProvider> = response.json().await?;
248255

249256
let mut all_models = Vec::new();
250257
for provider_id in supported_providers {
251-
if let Some(provider) = providers.get(*provider_id) {
258+
if let Some(provider) = providers.get(provider_id) {
252259
for (model_id, model) in &provider.models {
253260
let id = model.id.as_deref().unwrap_or(model_id);
254261
all_models.push(format!("{provider_id}:{id}"));

crates/rullm-cli/src/provider.rs

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -90,14 +90,4 @@ impl Provider {
9090
Provider::Google => "GOOGLE_AI_API_KEY",
9191
}
9292
}
93-
94-
pub fn models_dev_id(&self) -> &'static str {
95-
match self {
96-
Provider::OpenAI => "openai",
97-
Provider::Groq => "groq",
98-
Provider::OpenRouter => "openrouter",
99-
Provider::Anthropic => "anthropic",
100-
Provider::Google => "google",
101-
}
102-
}
10393
}

0 commit comments

Comments
 (0)