From 9db5c7af9ee06693f9c77475b5f0393766877cd5 Mon Sep 17 00:00:00 2001 From: pap Date: Mon, 28 Jul 2025 23:21:49 +0100 Subject: [PATCH] remove preference ranking as we don't get models dynamically --- codex-rs/core/src/openai_model_info.rs | 31 ------------------- .../src/bottom_pane/model_selection_view.rs | 12 +++---- codex-rs/tui/src/chatwidget.rs | 10 +++--- 3 files changed, 10 insertions(+), 43 deletions(-) diff --git a/codex-rs/core/src/openai_model_info.rs b/codex-rs/core/src/openai_model_info.rs index 1dcd7c19b5..f0e4355305 100644 --- a/codex-rs/core/src/openai_model_info.rs +++ b/codex-rs/core/src/openai_model_info.rs @@ -73,43 +73,12 @@ pub(crate) fn get_model_info(name: &str) -> Option { /// Return a curated list of commonly-used OpenAI model names for selection UIs. pub fn get_all_model_names() -> Vec<&'static str> { vec![ - // codex models "codex-mini-latest", - // reasoning models "o3", "o4-mini", - // GPT-4.1 family "gpt-4.1", - // GPT-4o family (canonical plus a few snapshots) "gpt-4o", ] } -/// Sort order by preference groups, then alphabetically. -pub fn preference_rank(name: &str) -> u8 { - // Lower is more preferred. - if name == "codex-mini-latest" { - return 0; - } - if name.starts_with("o4-mini") { - return 1; - } - if name == "o3" || name.starts_with("o3") { - return 2; - } - if name == "gpt-4.1" || name.starts_with("gpt-4.1") { - return 3; - } - // Handle both spellings just in case. - if name == "gpt4-o" || name.starts_with("gpt-4o") { - return 4; - } - 5 -} -/// Compare two model names by preference ranking. -pub fn compare_models_by_preference(a: &str, b: &str) -> std::cmp::Ordering { - preference_rank(a) - .cmp(&preference_rank(b)) - .then_with(|| a.cmp(b)) -} diff --git a/codex-rs/tui/src/bottom_pane/model_selection_view.rs b/codex-rs/tui/src/bottom_pane/model_selection_view.rs index 15714c2b45..4ed2675a48 100644 --- a/codex-rs/tui/src/bottom_pane/model_selection_view.rs +++ b/codex-rs/tui/src/bottom_pane/model_selection_view.rs @@ -21,7 +21,6 @@ use crate::app_event_sender::AppEventSender; use super::BottomPane; use super::BottomPaneView; -use codex_core::openai_model_info::compare_models_by_preference; /// Simple dropdown to select a model. pub(crate) struct ModelSelectionView { @@ -54,16 +53,15 @@ impl ModelSelectionView { /// sort preference, and search filter. fn build_display_rows(&self) -> Vec { // Determine candidate list excluding the current model (it is always pinned first). - let mut others: Vec<&str> = self + let others: Vec<&str> = self .options .iter() .map(|s| s.as_str()) .filter(|m| *m != self.current_model) .collect(); - // If not searching, apply preference sort; otherwise, we'll score by fuzzy match. + // If not searching, maintain provided ordering; otherwise, we'll score by fuzzy match. if self.query.is_empty() { - others.sort_by(|a, b| compare_models_by_preference(a, b)); let mut rows: Vec = Vec::new(); // Pinned current model always first. rows.push(DisplayRow::Model { @@ -99,11 +97,10 @@ impl ModelSelectionView { matches.push((name.to_string(), indices, score)); } } - // Sort by score (ascending => better). If equal, fall back to preference then alphabetical. + // Sort by score (ascending => better). If equal, fall back to alphabetical and match tightness. matches.sort_by(|(a_name, a_idx, a_score), (b_name, b_idx, b_score)| { a_score .cmp(b_score) - .then_with(|| compare_models_by_preference(a_name, b_name)) .then_with(|| a_name.cmp(b_name)) .then_with(|| a_idx.len().cmp(&b_idx.len())) }); @@ -415,8 +412,7 @@ impl<'a> BottomPaneView<'a> for ModelSelectionView { unique.push(m); } } - // Sort by preference for stable display when query is empty. - unique.sort_by(|a, b| compare_models_by_preference(a, b)); + // Preserve provided ordering without applying preference ranking. self.options = unique; // Clamp selection to available rows. diff --git a/codex-rs/tui/src/chatwidget.rs b/codex-rs/tui/src/chatwidget.rs index eaad5c5036..4dc9459f07 100644 --- a/codex-rs/tui/src/chatwidget.rs +++ b/codex-rs/tui/src/chatwidget.rs @@ -504,14 +504,16 @@ impl ChatWidget<'_> { let config_path = self.config.codex_home.join("config.toml"); if let Ok(contents) = std::fs::read_to_string(&config_path) { if let Ok(cfg) = toml::from_str::(&contents) { - if let Some(m) = cfg.model { - options.push(m); - } + let mut config_models: Vec = Vec::new(); + if let Some(m) = cfg.model { config_models.push(m); } for (_name, profile) in cfg.profiles.into_iter() { if let Some(m) = profile.model { - options.push(m); + config_models.push(m); } } + // Keep it simple and deterministic: alphabetical ordering for config models. + config_models.sort(); + options.extend(config_models); } }