-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Swap canonical model from openrouter to models.dev #6625
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
9268307
ed68894
a5e807e
f327622
56dd2a5
4c8b08b
a8d202c
2c19b24
078566b
87ce2eb
248e69c
cc848de
4500c26
d93c35d
b2b50bc
ca1a514
edbe3ed
03c3f5b
88a7ec5
582d9cd
6cf36f3
c9efc8f
dd41da5
f0d40cd
dc25cb3
c2f6376
ddffc7e
323f8ea
2a9837f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -42,9 +42,9 @@ pub struct ModelInfo { | |
| pub name: String, | ||
| /// The maximum context length this model supports | ||
| pub context_limit: usize, | ||
| /// Cost per token for input (optional) | ||
| /// Cost per token for input in USD (optional) | ||
| pub input_token_cost: Option<f64>, | ||
| /// Cost per token for output (optional) | ||
| /// Cost per token for output in USD (optional) | ||
| pub output_token_cost: Option<f64>, | ||
| /// Currency for the costs (default: "$") | ||
| pub currency: Option<String>, | ||
|
|
@@ -456,15 +456,40 @@ pub trait Provider: Send + Sync { | |
|
|
||
| let provider_name = self.get_name(); | ||
|
|
||
| let recommended_models: Vec<String> = all_models | ||
| // Get all text-capable models with their release dates | ||
| let mut models_with_dates: Vec<(String, Option<String>)> = all_models | ||
| .iter() | ||
| .filter(|model| { | ||
| map_to_canonical_model(provider_name, model, registry) | ||
| .and_then(|canonical_id| registry.get(&canonical_id)) | ||
| .map(|m| m.input_modalities.contains(&"text".to_string())) | ||
| .unwrap_or(false) | ||
| .filter_map(|model| { | ||
| let canonical_id = map_to_canonical_model(provider_name, model, registry)?; | ||
|
|
||
| let (provider, model_name) = canonical_id.split_once('/')?; | ||
| let canonical_model = registry.get(provider, model_name)?; | ||
|
|
||
| if !canonical_model | ||
| .modalities | ||
| .input | ||
| .contains(&crate::providers::canonical::Modality::Text) | ||
| { | ||
| return None; | ||
| } | ||
|
|
||
| let release_date = canonical_model.release_date.clone(); | ||
|
|
||
| Some((model.clone(), release_date)) | ||
| }) | ||
| .cloned() | ||
| .collect(); | ||
|
|
||
| // Sort by release date (most recent first), then alphabetically for models without dates | ||
| models_with_dates.sort_by(|a, b| match (&a.1, &b.1) { | ||
| (Some(date_a), Some(date_b)) => date_b.cmp(date_a), | ||
| (Some(_), None) => std::cmp::Ordering::Less, | ||
| (None, Some(_)) => std::cmp::Ordering::Greater, | ||
| (None, None) => a.0.cmp(&b.0), | ||
| }); | ||
|
Comment on lines
+483
to
+488
|
||
|
|
||
| let recommended_models: Vec<String> = models_with_dates | ||
| .into_iter() | ||
| .map(|(name, _)| name) | ||
| .collect(); | ||
|
|
||
| if recommended_models.is_empty() { | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
needing this comment suggests that we need to refactor this more either at the beginning or at the end - let's have one unit we pass around
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My followup pr deletes the pricing API and replaces it with a full canonical model fetch (or at least just the fields the client needs, but gives us a place to layer on more). will keep as cost / mtokens until we render.