Skip to content

Commit 0ab49c6

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

3 files changed

Lines changed: 12 additions & 16 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 & 5 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

@@ -236,19 +237,24 @@ struct ModelsDevProvider {
236237

237238
#[derive(Deserialize)]
238239
struct ModelsDevModel {
239-
#[serde(default)]
240240
id: Option<String>,
241241
}
242242

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

249255
let mut all_models = Vec::new();
250256
for provider_id in supported_providers {
251-
if let Some(provider) = providers.get(*provider_id) {
257+
if let Some(provider) = providers.get(provider_id) {
252258
for (model_id, model) in &provider.models {
253259
let id = model.id.as_deref().unwrap_or(model_id);
254260
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)