diff --git a/docs/llm-model-configs-api.md b/docs/llm-model-configs-api.md index e61613b60..5a867e4b2 100644 --- a/docs/llm-model-configs-api.md +++ b/docs/llm-model-configs-api.md @@ -167,9 +167,9 @@ The `model_type` field accepts the following values: | `total` | integer | Total count | **Default Configuration Selection Logic:** -1. User's config marked with `is_default: true` -2. Group's config marked with `is_default: true` (if user has no default) -3. First config in the list (fallback if no default is marked) +1. User's config marked with `is_default: true` (highest priority) +2. Group's config marked with `is_default: true` +3. First config in the list (user configs come before group configs) ### LLMModelConfigListResponse diff --git a/gns3server/db/repositories/llm_model_configs.py b/gns3server/db/repositories/llm_model_configs.py index 3d7cbe818..af40042e0 100644 --- a/gns3server/db/repositories/llm_model_configs.py +++ b/gns3server/db/repositories/llm_model_configs.py @@ -476,9 +476,6 @@ class LLMModelConfigsRepository(BaseRepository): "group_name": None }) - if config.is_default and default_config is None: - default_config = configs_with_source[-1] - # Add inherited group configs (always shown, regardless of user configs) for group_id, configs in group_configs_map.items(): for config in configs: @@ -503,10 +500,22 @@ class LLMModelConfigsRepository(BaseRepository): "group_name": group_names_map[group_id] }) - if config.is_default and default_config is None: - default_config = configs_with_source[-1] + # Select default_config with proper priority: + # 1. User's config marked with is_default: true + # 2. Group's config marked with is_default: true + # 3. First config in the list (user configs come first) + for config in configs_with_source: + if config["is_default"] and config["source"] == "user": + default_config = config + break - # Fallback: if no config is marked as default, use the first one + if default_config is None: + for config in configs_with_source: + if config["is_default"] and config["source"] == "group": + default_config = config + break + + # Fallback to first config if no default is marked if default_config is None and configs_with_source: default_config = configs_with_source[0]