Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 16 additions & 2 deletions app/src/ai/blocklist/inline_action/orchestration_controls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -454,10 +454,23 @@ pub fn populate_model_picker_for_harness<A: OrchestrationControlAction, V: View>
let harness = Harness::parse_orchestration_harness(&harness_type);
match harness {
Some(Harness::Oz) | None => {
// Oz / unset: current behavior — Warp LLM catalog.
// Oz / unset: Warp LLM catalog. Custom models excluded for
// cloud runs (not supported by remote workers).
// Order: auto models first, then custom models, then other models.
let llm_prefs = LLMPreferences::as_ref(ctx_dropdown);
let choices: Vec<_> = llm_prefs
let all_choices: Vec<_> = llm_prefs
.get_base_llm_choices_for_agent_mode(ctx_dropdown)
.filter(|llm| is_local || !llm.is_custom_endpoint())
.collect();
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need to collect into a Vec here? That's a memory allocation that I don't think we need here, since the only time we use all_choices we immediately transform it back into an iterator using into_iter().

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nope, not needed.
removed

let (auto_models, rest): (Vec<_>, Vec<_>) = all_choices
.into_iter()
.partition(|llm| llm.id.as_str().starts_with("auto"));
let (custom_models, other_models): (Vec<_>, Vec<_>) =
rest.into_iter().partition(|llm| llm.is_custom_endpoint());
let choices: Vec<_> = auto_models
.into_iter()
.chain(custom_models)
.chain(other_models)
.collect();
let selected_display_name = choices
.iter()
Expand Down Expand Up @@ -548,6 +561,7 @@ pub fn is_model_in_filtered_choices<V: View>(
let llm_prefs = LLMPreferences::as_ref(ctx);
llm_prefs
.get_base_llm_choices_for_agent_mode(ctx)
.filter(|llm| is_local || !llm.is_custom_endpoint())
.any(|llm| llm.id.to_string() == model_id)
}
Some(Harness::Codex) if is_local => model_id.is_empty(),
Expand Down
7 changes: 7 additions & 0 deletions app/src/ai/llms.rs
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,13 @@ impl LLMInfo {
self.reasoning_level.clone()
}

/// Returns true if this is a custom inference endpoint model.
pub fn is_custom_endpoint(&self) -> bool {
self.description
.as_ref()
.is_some_and(|d| d.starts_with("Custom · "))
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 [SUGGESTION] This makes custom-endpoint detection depend on a user-facing description prefix. Prefer filtering via LLMPreferences::custom_llm_info_for_id(&llm.id).is_some() at the call sites so copy changes or a server model with the same prefix cannot change cloud model eligibility.

}

#[cfg(feature = "integration_tests")]
fn new_for_test(llm_name: &str) -> Self {
Self {
Expand Down
61 changes: 61 additions & 0 deletions app/src/ai/llms_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -303,3 +303,64 @@ fn removing_endpoint_purges_all_its_models_from_custom_llms() {
assert_eq!(infos.len(), 1);
assert_eq!(infos[0].id.as_str(), "uuid-k1");
}

#[test]
fn is_custom_endpoint_true_for_custom_models() {
let keys = ai::api_keys::ApiKeys {
custom_endpoints: vec![endpoint(
"My Endpoint",
"https://x.io",
"k",
vec![model("gpt-4", None, "uuid-1")],
)],
..Default::default()
};
let infos = build_custom_llm_infos(&keys);
assert!(infos[0].is_custom_endpoint());
}

#[test]
fn is_custom_endpoint_false_for_regular_models() {
let info = LLMInfo {
display_name: "claude-4".into(),
base_model_name: "claude-4".into(),
id: "claude-4".into(),
reasoning_level: None,
usage_metadata: LLMUsageMetadata {
request_multiplier: 1,
credit_multiplier: None,
},
description: Some("Anthropic model".into()),
disable_reason: None,
vision_supported: true,
spec: None,
provider: LLMProvider::Anthropic,
host_configs: HashMap::new(),
discount_percentage: None,
context_window: LLMContextWindow::default(),
};
assert!(!info.is_custom_endpoint());
}

#[test]
fn is_custom_endpoint_false_for_no_description() {
let info = LLMInfo {
display_name: "claude-4".into(),
base_model_name: "claude-4".into(),
id: "claude-4".into(),
reasoning_level: None,
usage_metadata: LLMUsageMetadata {
request_multiplier: 1,
credit_multiplier: None,
},
description: None,
disable_reason: None,
vision_supported: true,
spec: None,
provider: LLMProvider::Unknown,
host_configs: HashMap::new(),
discount_percentage: None,
context_window: LLMContextWindow::default(),
};
assert!(!info.is_custom_endpoint());
}
17 changes: 6 additions & 11 deletions app/src/terminal/view/ambient_agent/model_selector.rs
Original file line number Diff line number Diff line change
Expand Up @@ -468,41 +468,36 @@ impl ModelSelector {
.clone();

let mut auto_choices = Vec::new();
let mut custom_choices = Vec::new();
let mut other_choices = Vec::new();
for llm in llm_preferences.get_base_llm_choices_for_agent_mode(ctx) {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we use the common get_base_model_choices method here as well?

if llm_preferences.custom_llm_info_for_id(&llm.id).is_some() {
continue;
}

let display_name = llm.menu_display_name();
if !query.is_empty() && !display_name.to_lowercase().contains(query) {
continue;
}
if is_auto(llm) {
auto_choices.push(llm);
} else if llm_preferences.custom_llm_info_for_id(&llm.id).is_some() {
custom_choices.push(llm);
} else {
other_choices.push(llm);
}
}

let items: Vec<MenuItem<ModelSelectorAction>> = auto_choices
.into_iter()
.chain(custom_choices)
.chain(other_choices)
.map(|llm| {
let display_name = llm.menu_display_name();
let is_custom = llm_preferences.custom_llm_info_for_id(&llm.id).is_some();
let mut fields = MenuItemFields::new(display_name)
let fields = MenuItemFields::new(display_name)
.with_icon(llm.provider.icon().unwrap_or(Icon::Oz))
.with_icon_size_override(ITEM_ICON_SIZE)
.with_font_size_override(ITEM_FONT_SIZE)
.with_padding_override(ITEM_VERTICAL_PADDING, MENU_HORIZONTAL_PADDING)
.with_override_hover_background_color(hover_background)
.with_on_select_action(ModelSelectorAction::SelectModel(llm.id.clone()))
.with_disabled(llm.disable_reason.is_some());
if is_custom {
fields = fields.with_right_side_icon(Icon::Key);
} else {
fields = fields.with_icon(llm.provider.icon().unwrap_or(Icon::Oz));
}
MenuItem::Item(fields)
})
.collect();
Expand Down