Repository navigation
Fix: model selection format compat and provider api_key wrapping - #17112
Conversation
📝 WalkthroughWalkthroughModel selection now supports composed identity values when IDs are unavailable, and default-model requests accept either IDs or provider-specific fields. Provider configuration transforms also nest auxiliary metadata inside ChangesModel configuration flow
Sequence Diagram(s)sequenceDiagram
participant SystemSetting
participant parseModelValue
participant setDefaultModel
SystemSetting->>parseModelValue: parse selected model value
parseModelValue-->>SystemSetting: parsed identity or fallback
SystemSetting->>setDefaultModel: persist model type and identity
Possibly related PRs
Suggested reviewers: Poem
🚥 Pre-merge checks | ✅ 3 | ❌ 2❌ Failed checks (1 warning, 1 inconclusive)
✅ Passed checks (3 passed)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In
`@web/src/pages/user-setting/setting-model/provider-schema/field-config/generic-api-key-config.ts`:
- Around line 80-89: Update the submitTransform function to include
values.model_info in its returned payload, preserving the model_info data
supplied by the parent hook while keeping the existing instance_name, api_key,
and api_base transformations unchanged.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: c4988839-1267-4ad3-ba34-750bfa2be512
📒 Files selected for processing (7)
web/src/components/model-tree-select.tsxweb/src/hooks/use-llm-request.tsxweb/src/interfaces/request/llm.tsweb/src/pages/user-setting/setting-model/layout/system-setting.tsxweb/src/pages/user-setting/setting-model/provider-schema/field-config/generic-api-key-config.tsweb/src/pages/user-setting/setting-model/provider-schema/field-config/local-llm-configs.tsweb/src/pages/user-setting/setting-model/provider-schema/field-config/provider-config-map.ts
| submitTransform: (values) => { | ||
| const apiKey = values.group_id | ||
| ? { api_key: values.api_key ?? '', group_id: values.group_id } | ||
| : (values.api_key ?? ''); | ||
| return { | ||
| instance_name: values.instance_name, | ||
| api_key: apiKey, | ||
| api_base: values.base_url || '', | ||
| }; | ||
| }, |
There was a problem hiding this comment.
🗄️ Data Integrity & Integration | 🟠 Major | ⚡ Quick win
Include model_info in the submitted payload to satisfy the API contract.
The new submitTransform object drops the model_info field. Because the parent hook invokes this transform by spreading model_info into values (i.e. submitTransform({ ...values, model_info: modelInfoList })), omitting it here strips it from the final payload sent to the backend. This violates the IAddLlmRequestBody interface.
Please pass model_info through, just as it is explicitly handled in the other provider configurations.
🐛 Proposed fix
submitTransform: (values) => {
const apiKey = values.group_id
? { api_key: values.api_key ?? '', group_id: values.group_id }
: (values.api_key ?? '');
return {
instance_name: values.instance_name,
api_key: apiKey,
api_base: values.base_url || '',
+ model_info: values.model_info || [],
};
},📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| submitTransform: (values) => { | |
| const apiKey = values.group_id | |
| ? { api_key: values.api_key ?? '', group_id: values.group_id } | |
| : (values.api_key ?? ''); | |
| return { | |
| instance_name: values.instance_name, | |
| api_key: apiKey, | |
| api_base: values.base_url || '', | |
| }; | |
| }, | |
| submitTransform: (values) => { | |
| const apiKey = values.group_id | |
| ? { api_key: values.api_key ?? '', group_id: values.group_id } | |
| : (values.api_key ?? ''); | |
| return { | |
| instance_name: values.instance_name, | |
| api_key: apiKey, | |
| api_base: values.base_url || '', | |
| model_info: values.model_info || [], | |
| }; | |
| }, |
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In
`@web/src/pages/user-setting/setting-model/provider-schema/field-config/generic-api-key-config.ts`
around lines 80 - 89, Update the submitTransform function to include
values.model_info in its returned payload, preserving the model_info data
supplied by the parent hook while keeping the existing instance_name, api_key,
and api_base transformations unchanged.
wangq8
left a comment
There was a problem hiding this comment.
Review: PR #17112
Title: Fix: model selection format compat and provider api_key wrapping
Author: @dcc123456
Files: 7 files, +76/-34
Overview
This PR addresses two issues: (1) models missing a model_id field now fall back to a composite identifier built from model_name/instance_name/provider_name, and (2) provider API key submission now supports passing extra metadata (e.g., group_id, provider_order, api_version) by wrapping api_key as an object when these extras are present.
✅ What works well
- The
model_idfallback inmodel-tree-select.tsxanduse-llm-request.tsxis clean and backward-compatible — whenmodel_idexists, behavior is unchanged. - The union type
ISetDefaultModelRequestBodyis well-typed and preserves the legacy interface. - The api_key wrapping is non-breaking when no extra fields are present (falls back to a plain string).
⚠️ Concerns
1. Backend compatibility of api_key wrapping (medium risk)
The most significant change is structural: fields like group_id, api_version, and provider_order were previously sent as top-level request body keys. Now they are nested inside the api_key object. This means:
generic-api-key-config.ts:group_idandmax_tokens: 0removed from top-level,group_idembedded inapi_keyobject.local-llm-configs.ts:provider_orderremoved from top-level, embedded inapi_keyobject.provider-config-map.ts(Azure):api_versionremoved from top-level, embedded inapi_keyobject.
👉 This will silently break if the backend endpoint parses these fields from the top-level request body. Please verify that the backend handlers (PUT /api/v1/llm/{factory}/instance and related) have been updated (or already accept) this nested format.
2. Type safety of the union request body (low risk)
In system-setting.tsx, parseModelValue(value) returns { model_name, model_instance, model_provider } | null. If the returned object contains unexpected extra keys or the backend expects a strictly exact shape, the request may silently fail. Consider adding an explicit assertion or interface validation.
3. No tests (minor)
No test files are included. Given the non-trivial transformations in the submitTransform functions, at least a basic unit test on the api_key wrapping logic would improve confidence.
4. max_tokens: 0 removal (nit)
The generic-api-key-config.ts previously sent max_tokens: 0 as a top-level field. It has been removed entirely. If this was intentional cleanup, please confirm — if the backend defaults it, no issue.
Summary
The overall direction is good — both fixes are sensible improvements. The main concern is backend alignment for the api_key wrapping. As long as the receiving endpoints handle the nested format, this should be ready to merge after verification.
Summary
Fix: model selection format compat and provider api_key wrapping