From 7a2d15cb64ed3a7de1c7e80577e3e3d56a815aab Mon Sep 17 00:00:00 2001 From: YueGuobin Date: Tue, 3 Mar 2026 22:56:21 +0800 Subject: [PATCH] feat: clarify default LLM model config selection logic Updated documentation and implementation to clearly define the priority order for selecting default LLM model configurations. The logic now explicitly states: 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) This ensures consistent behavior between the API documentation and the actual implementation in the repository code. --- docs/llm-model-configs-api.md | 6 +++--- .../db/repositories/llm_model_configs.py | 21 +++++++++++++------ 2 files changed, 18 insertions(+), 9 deletions(-) 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]