Repository navigation
fix: show default embedding model when provider is not yet registered - #15511
Conversation
📝 WalkthroughWalkthroughAccept bare model names (default instance "default"), add TEI Builtin embedding detection and handling across model resolution, availability checks, and tenant-added listing, and remove default TEI image assignments in docker/.env. ChangesTEI Builtin Embedding Configuration and Resolution
Sequence DiagramsequenceDiagram
participant Client
participant ModelsAPI as models_api_service
participant TenantService as tenant_model_service
participant Config as Environment_Config
Client->>ModelsAPI: _get_model_info(model_string)
ModelsAPI->>ModelsAPI: parse model string -> provider="", instance="default"
Config->>ModelsAPI: check COMPOSE_PROFILES and TEI_MODEL
alt TEI Builtin matched and provider falsy/"Builtin"
ModelsAPI->>ModelsAPI: return Builtin provider, instance "default"
else
ModelsAPI->>TenantService: get_model_config_from_provider_instance(...)
TenantService->>TenantService: accept provider=="Builtin" or falsy for TEI
TenantService->>ModelsAPI: return config
ModelsAPI->>Client: return model info
end
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related PRs
Suggested labels
Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. Warning Review ran into problems🔥 ProblemsGit: Failed to clone repository. Please run the 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
🧹 Nitpick comments (1)
api/apps/services/models_api_service.py (1)
48-89: ⚡ Quick winAdd logging to this new resolution flow.
The helper resolves (or fails to resolve) a tenant's default model but emits no log on either path, unlike the surrounding code which logs misses (e.g. lines 145, 166). A debug log on a successful resolve and on the
return Nonepath would aid diagnosing why a default model does/doesn't appear.As per coding guidelines: "Add logging for new flows".
🤖 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 `@api/apps/services/models_api_service.py` around lines 48 - 89, Add debug logging to _resolve_model_from_tenant_providers: when you return a resolved model (just before the return of the dict) log a debug message including tenant_id, provider_name, instance.instance_name, llm["llm_name"] and factory_type; and when falling through to return None (just before the final return None) log a debug message that resolution failed for the given tenant_id and model_type. Use the module's existing logger (or processLogger) and reference the same symbols used in the function (TenantModelProviderService, TenantModelInstanceService, FACTORY_LLM_INFOS, MODEL_TAG_TO_TYPE) so the logs clearly show which provider/instance/llm were considered.
🤖 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 `@api/apps/services/models_api_service.py`:
- Around line 56-89: The resolver _resolve_model_from_tenant_providers is
incorrectly reverse-mapping MODEL_TAG_TO_TYPE (creating type_to_tag and
tag_type) and then comparing llm.get("model_type") against tag_type, which
prevents matching internal types like "speech2text"/"image2text" defined in
FACTORY_LLM_INFOS; remove the reverse-mapping (type_to_tag and tag_type) and
instead compare llm.get("model_type") directly to the incoming model_type (or
factory_type) when building matching_llms so the lookup matches the internal
model_type values in FACTORY_LLM_INFOS.
---
Nitpick comments:
In `@api/apps/services/models_api_service.py`:
- Around line 48-89: Add debug logging to _resolve_model_from_tenant_providers:
when you return a resolved model (just before the return of the dict) log a
debug message including tenant_id, provider_name, instance.instance_name,
llm["llm_name"] and factory_type; and when falling through to return None (just
before the final return None) log a debug message that resolution failed for the
given tenant_id and model_type. Use the module's existing logger (or
processLogger) and reference the same symbols used in the function
(TenantModelProviderService, TenantModelInstanceService, FACTORY_LLM_INFOS,
MODEL_TAG_TO_TYPE) so the logs clearly show which provider/instance/llm were
considered.
🪄 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: e44715be-3fb4-44e5-ae42-b23af4255d26
📒 Files selected for processing (2)
api/apps/services/models_api_service.pyweb/src/hooks/use-llm-request.tsx
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #15511 +/- ##
=======================================
Coverage 93.16% 93.16%
=======================================
Files 10 10
Lines 717 717
Branches 118 118
=======================================
Hits 668 668
Misses 29 29
Partials 20 20 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Signed-off-by: noob <[email protected]>
5f6ff6b to
fa67a45
Compare
There was a problem hiding this comment.
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
api/apps/services/models_api_service.py (1)
301-307:⚠️ Potential issue | 🟠 Major | ⚡ Quick winTEI Builtin model can never be listed when tenant has no providers/instances.
list_tenant_added_modelsreturns early at Line 301 and Line 307, so the TEI append logic at Line 380 is skipped exactly in the “no provider” setup where Builtin TEI should still be discoverable.💡 Proposed fix
- providers = TenantModelProviderService.get_by_tenant_id(tenant_id) - if not providers: - return True, [] + providers = TenantModelProviderService.get_by_tenant_id(tenant_id) or [] + added_models = [] - provider_ids = [provider.id for provider in providers] - instances = TenantModelInstanceService.get_by_provider_ids(provider_ids) - if not instances: - return True, [] - provider_instance_map: dict = {} - provider_info_map = {provider.id: provider for provider in providers} - for provider_instance_record in instances: - provider_name = provider_info_map[provider_instance_record.provider_id].provider_name if provider_info_map.get(provider_instance_record.provider_id) else "" - if provider_instance_map.get(provider_name): - provider_instance_map[provider_name].append(provider_instance_record) - else: - provider_instance_map[provider_name] = [provider_instance_record] + if providers: + provider_ids = [provider.id for provider in providers] + instances = TenantModelInstanceService.get_by_provider_ids(provider_ids) or [] + provider_instance_map: dict = {} + provider_info_map = {provider.id: provider for provider in providers} + for provider_instance_record in instances: + provider_name = provider_info_map[provider_instance_record.provider_id].provider_name if provider_info_map.get(provider_instance_record.provider_id) else "" + if provider_instance_map.get(provider_name): + provider_instance_map[provider_name].append(provider_instance_record) + else: + provider_instance_map[provider_name] = [provider_instance_record] + + # keep existing provider/instance-based population logic hereAlso applies to: 380-398
🤖 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 `@api/apps/services/models_api_service.py` around lines 301 - 307, In list_tenant_added_models: the early returns when providers is empty or when instances is empty prevent the later Builtin TEI append logic from running; instead of returning True, [] in those checks, let the function continue with an empty providers/instances list so the TEI append block (the logic around the TEI append at ~lines 380-398) still executes. Concretely, update the checks around providers and TenantModelInstanceService.get_by_provider_ids(...) to avoid returning early (e.g., skip provider-specific processing when empty but continue) so Builtin TEI is discoverable even when no providers/instances exist.
🧹 Nitpick comments (1)
api/apps/services/models_api_service.py (1)
83-97: ⚡ Quick winAdd logs for new TEI Builtin resolution/listing paths.
These new branches introduce behavior changes but have no telemetry, which makes tenant-level model resolution/debugging harder.
As per coding guidelines,
**/*.py: Add logging for new flows.Also applies to: 380-398
🤖 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 `@api/apps/services/models_api_service.py` around lines 83 - 97, Add telemetry/logging around the TEI Builtin resolution branch so tenant-level model resolution is observable: inside the block that checks compose_profiles, tei_model, model_type, model_name and provider_name (the special-case branch using variables compose_profiles and tei_model) emit an info/debug log via the module logger that includes the resolved model_provider/model_instance/model_name/model_type and the compose_profiles/TEI_MODEL values; also add corresponding logs on the alternative path (when the TEI conditions are present but not matched) in the similar flow referenced around the other branch (the block at ~380-398) so both resolution and non-resolution paths are recorded for debugging.
🤖 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.
Outside diff comments:
In `@api/apps/services/models_api_service.py`:
- Around line 301-307: In list_tenant_added_models: the early returns when
providers is empty or when instances is empty prevent the later Builtin TEI
append logic from running; instead of returning True, [] in those checks, let
the function continue with an empty providers/instances list so the TEI append
block (the logic around the TEI append at ~lines 380-398) still executes.
Concretely, update the checks around providers and
TenantModelInstanceService.get_by_provider_ids(...) to avoid returning early
(e.g., skip provider-specific processing when empty but continue) so Builtin TEI
is discoverable even when no providers/instances exist.
---
Nitpick comments:
In `@api/apps/services/models_api_service.py`:
- Around line 83-97: Add telemetry/logging around the TEI Builtin resolution
branch so tenant-level model resolution is observable: inside the block that
checks compose_profiles, tei_model, model_type, model_name and provider_name
(the special-case branch using variables compose_profiles and tei_model) emit an
info/debug log via the module logger that includes the resolved
model_provider/model_instance/model_name/model_type and the
compose_profiles/TEI_MODEL values; also add corresponding logs on the
alternative path (when the TEI conditions are present but not matched) in the
similar flow referenced around the other branch (the block at ~380-398) so both
resolution and non-resolution paths are recorded for debugging.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 696719d3-6fc8-4dc0-9caf-f9c55ac945d6
📒 Files selected for processing (3)
api/apps/services/models_api_service.pyapi/db/joint_services/tenant_model_service.pydocker/.env
Signed-off-by: noob <[email protected]>
There was a problem hiding this comment.
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
docker/.env (1)
20-20:⚠️ Potential issue | 🟡 Minor | ⚡ Quick winSet
DOC_ENGINEdefault toinfinityin this file.
DOC_ENGINEis still defaulting toelasticsearch; this file-level setting should be updated toinfinityto match repository guidance.-DOC_ENGINE=${DOC_ENGINE:-elasticsearch} +DOC_ENGINE=${DOC_ENGINE:-infinity}As per coding guidelines "Set DOC_ENGINE=infinity in docker/.env to switch from Elasticsearch (default) to Infinity with container restart".
🤖 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 `@docker/.env` at line 20, Update the docker/.env file to change the DOC_ENGINE default value from "elasticsearch" to "infinity": locate the DOC_ENGINE declaration (DOC_ENGINE=${DOC_ENGINE:-elasticsearch}) and modify it so the fallback/default is "infinity" (i.e., replace the current default token "elasticsearch" with "infinity") to align with repository guidance.
🤖 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.
Outside diff comments:
In `@docker/.env`:
- Line 20: Update the docker/.env file to change the DOC_ENGINE default value
from "elasticsearch" to "infinity": locate the DOC_ENGINE declaration
(DOC_ENGINE=${DOC_ENGINE:-elasticsearch}) and modify it so the fallback/default
is "infinity" (i.e., replace the current default token "elasticsearch" with
"infinity") to align with repository guidance.
Signed-off-by: noob <[email protected]>
What problem does this PR solve?
Problem
On the Model Providers page, the Embedding Model dropdown in System Model Settings shows empty (no default selected), even though a default embedding model is configured in
service_conf.yaml.Root Cause
Two issues were identified:
Backend:
_get_model_infofails for unregistered providersThe tenant's
embd_idis set tobge-m3@xxxxduring initialization (from the placeholder configfactory: 'xxxx'). The_get_model_infofunction requires the provider to exist intenant_model_providertable, butxxxxis never a real provider. Even after the user adds a real provider (e.g., ZHIPU-AI), the staleembd_idstill references the non-existent one, causing the function to returnNone.Frontend: default models cache not invalidated after adding provider
useAddProviderInstanceonly invalidatesaddedProvidersandallModelscaches after adding a provider instance, but does not invalidate thedefaultModelscache. This means the default model list is not re-fetched until the user manually refreshes the page.Fix
api/apps/services/models_api_service.py_resolve_model_from_tenant_providers()helper: when the default model's provider doesn't exist (e.g., placeholderxxxx), it searches through the tenant's actually registered providers for a model of the same type and returns the first match."default"vs actual name"1"), the function now auto-resolves to the first real instance under that provider.FACTORY_LLM_INFOSvalidation when neither provider nor instance exists.web/src/hooks/use-llm-request.tsxqueryClient.invalidateQueries({ queryKey: LlmKeys.defaultModels() })touseAddProviderInstanceso that the default model list is re-fetched immediately after a provider instance is added, eliminating the need for a manual page refresh.Testing
embd_id=bge-m3@xxxxand only provider is ZHIPU-AI (instance1):_resolve_model_from_tenant_providerscorrectly resolves toembedding-2@1@ZHIPU-AI.Type of change