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.
This commit is contained in:
YueGuobin 2026-03-03 22:56:21 +08:00
parent f4723cd083
commit 7a2d15cb64
2 changed files with 18 additions and 9 deletions

View File

@ -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

View File

@ -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]