Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
11 changes: 10 additions & 1 deletion app/src/ai/llms.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1180,7 +1180,10 @@ impl LLMPreferences {
let effective_base_model_usable = self
.models_by_feature
.agent_mode
.usable_info_for_id(effective_base_model_id, ctx);
.usable_info_for_id(effective_base_model_id, ctx)
.or_else(|| {
self.custom_llm_info_for_id_if_enabled(effective_base_model_id, ctx)
});
let effective_base_model_unusable = effective_base_model_usable.is_none();
let effective_base_model_is_configurable = effective_base_model_usable
.is_some_and(|info| info.context_window.is_configurable);
Expand All @@ -1199,6 +1202,9 @@ impl LLMPreferences {
.models_by_feature
.coding
.usable_info_for_id(preferred_llm_id, ctx)
.or_else(|| {
self.custom_llm_info_for_id_if_enabled(preferred_llm_id, ctx)
})
.is_none()
{
profiles.set_coding_model(profile_id, None, ctx);
Expand All @@ -1208,6 +1214,9 @@ impl LLMPreferences {
if self
.get_cli_agent_available()
.usable_info_for_id(preferred_llm_id, ctx)
.or_else(|| {
self.custom_llm_info_for_id_if_enabled(preferred_llm_id, ctx)
})
.is_none()
{
profiles.set_cli_agent_model(profile_id, None, ctx);
Expand Down
77 changes: 77 additions & 0 deletions app/src/ai/llms_tests.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,21 @@
use super::*;

use warpui::App;

use crate::ai::execution_profiles::profiles::AIExecutionProfilesModel;
use crate::ai::mcp::TemplatableMCPServerManager;
use crate::auth::auth_manager::AuthManager;
use crate::auth::AuthStateProvider;
use crate::cloud_object::model::persistence::CloudModel;
use crate::network::NetworkStatus;
use crate::server::cloud_objects::update_manager::UpdateManager;
use crate::server::server_api::ServerApiProvider;
use crate::server::sync_queue::SyncQueue;
use crate::test_util::settings::initialize_settings_for_tests;
use crate::workspaces::team_tester::TeamTesterStatus;
use crate::workspaces::user_workspaces::UserWorkspaces;
use crate::LaunchMode;

// -- DisableReason::should_clear_preference tests --

#[test]
Expand Down Expand Up @@ -303,3 +319,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 reconcile_preserves_custom_models_saved_on_execution_profile() {
App::test((), |mut app| async move {
let _custom_inference_flag = FeatureFlag::CustomInferenceEndpoints.override_enabled(true);

initialize_settings_for_tests(&mut app);
app.add_singleton_model(|_| ServerApiProvider::new_for_test());
app.add_singleton_model(|_| AuthStateProvider::new_for_test());
app.add_singleton_model(AuthManager::new_for_test);
app.add_singleton_model(|_| NetworkStatus::new());
app.add_singleton_model(UserWorkspaces::default_mock);
app.add_singleton_model(CloudModel::mock);
app.add_singleton_model(TeamTesterStatus::mock);
app.add_singleton_model(SyncQueue::mock);
app.add_singleton_model(UpdateManager::mock);
app.add_singleton_model(|_| TemplatableMCPServerManager::default());

let profiles_model = app.add_singleton_model(|ctx| {
AIExecutionProfilesModel::new(&LaunchMode::new_for_unit_test(), ctx)
});
let llm_preferences = app.add_singleton_model(LLMPreferences::new);

let custom_model_id = LLMId::from("custom-model-config-key");
ApiKeyManager::handle(&app).update(&mut app, |api_key_manager, ctx| {
api_key_manager.add_custom_endpoint(
"local".to_string(),
"https://example.com/v1".to_string(),
"test-key".to_string(),
vec![(
"custom-model".to_string(),
Some("Custom Model".to_string()),
Some(custom_model_id.to_string()),
)],
ctx,
);
});

let default_profile_id =
profiles_model.read(&app, |profiles, _| profiles.default_profile_id());
profiles_model.update(&mut app, |profiles, ctx| {
profiles.set_base_model(default_profile_id, Some(custom_model_id.clone()), ctx);
profiles.set_coding_model(default_profile_id, Some(custom_model_id.clone()), ctx);
profiles.set_cli_agent_model(default_profile_id, Some(custom_model_id.clone()), ctx);
});

llm_preferences.update(&mut app, |preferences, ctx| {
preferences.update_feature_model_choices(Ok(ModelsByFeature::default()), ctx);
});

profiles_model.read(&app, |profiles, ctx| {
let profile = profiles.default_profile(ctx);
assert_eq!(profile.data().base_model.as_ref(), Some(&custom_model_id));
assert_eq!(profile.data().coding_model.as_ref(), Some(&custom_model_id));
assert_eq!(
profile.data().cli_agent_model.as_ref(),
Some(&custom_model_id)
);
});
});
}
Loading