From 2e4c42fadcc0b3d339e827288115e41b82c6a29d Mon Sep 17 00:00:00 2001 From: YueGuobin Date: Tue, 3 Mar 2026 22:27:28 +0800 Subject: [PATCH] feat(api): clarify default LLM model config selection logic - Update API documentation to explicitly describe default configuration selection logic - Add fallback behavior in repository to use first config when no default is marked - Clarify difference between `/default` endpoint and `default_config` field - Document that `default_config` is never null when configs list is not empty --- docs/llm-model-configs-api.md | 15 ++++++++++++++- gns3server/db/repositories/llm_model_configs.py | 4 ++++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/docs/llm-model-configs-api.md b/docs/llm-model-configs-api.md index a19086251..b1ad9f1b8 100644 --- a/docs/llm-model-configs-api.md +++ b/docs/llm-model-configs-api.md @@ -161,9 +161,14 @@ The `model_type` field accepts the following values: | Field | Type | Description | |-------|------|-------------| | `configs` | list[LLMModelConfigWithSource] | Effective configurations | -| `default_config` | LLMModelConfigWithSource (nullable) | Default configuration | +| `default_config` | LLMModelConfigWithSource (nullable) | Default configuration (never null if configs list is not empty) | | `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) + ### LLMModelConfigWithSource | Field | Type | Description | @@ -368,6 +373,8 @@ curl -X GET http://localhost:3080/v3/access/users/{user_id}/llm-model-configs/de -H "Authorization: Bearer " ``` +**Note:** This endpoint only returns configurations explicitly marked with `is_default: true`. If no configuration is marked as default, it returns 404. + **Response:** ```json { @@ -408,6 +415,12 @@ curl -X GET http://localhost:3080/v3/access/groups/{group_id}/llm-model-configs/ The response format is the same as for users. +--- + +**Important Note:** This dedicated `/default` endpoint is different from the `default_config` field in the list response: +- `/default` endpoint: Requires explicit `is_default: true` flag, returns 404 if not found +- `default_config` field in list: Falls back to first config if no explicit default is marked + ### 8. Delete a configuration ```bash diff --git a/gns3server/db/repositories/llm_model_configs.py b/gns3server/db/repositories/llm_model_configs.py index a1753a0b0..3517f6b52 100644 --- a/gns3server/db/repositories/llm_model_configs.py +++ b/gns3server/db/repositories/llm_model_configs.py @@ -496,6 +496,10 @@ class LLMModelConfigsRepository(BaseRepository): if config.is_default and default_config is None: default_config = configs_with_source[-1] + # Fallback: if no config is marked as default, use the first one + if default_config is None and configs_with_source: + default_config = configs_with_source[0] + return { "configs": configs_with_source, "default_config": default_config