Repository navigation
Fix: allow use image2text as chat model - #14331
Conversation
📝 WalkthroughWalkthrough
Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Possibly related PRs
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. 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: 2
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@api/db/joint_services/tenant_model_service.py`:
- Around line 74-79: The current type-check skips mismatch validation for all
CHAT requests; restrict this so CHAT only accepts an IMAGE2TEXT fallback. In the
block using config_model_type and model_type_val (and LLMType.CHAT), change the
condition so that when model_type_val == LLMType.CHAT.value you allow
config_model_type == model_type_val OR config_model_type ==
LLMType.IMAGE2TEXT.value, otherwise enforce exact equality and raise the same
LookupError (refer to config_model_type, model_type_val, and LLMType.CHAT /
LLMType.IMAGE2TEXT).
- Around line 60-65: The CHAT branch currently skips the pure-name CHAT retry;
change the logic in the block guarding model_type_val == LLMType.CHAT.value to
first attempt TenantLLMService.get_api_key(tenant_id, pure_model_name,
LLMType.CHAT.value) and only if that returns falsy then try
TenantLLMService.get_api_key(tenant_id, pure_model_name,
LLMType.IMAGE2TEXT.value); when falling back to IMAGE2TEXT emit a log via
logging (import logging at top) saying you're promoting an IMAGE2TEXT model to
CHAT so operators can see the multimodal fallback; keep populating config_dict
from model_config.to_dict() as before and raise the same LookupError if both
lookups fail.
🪄 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: da49cb23-3db2-465f-80ee-774b4069bfcf
📒 Files selected for processing (1)
api/db/joint_services/tenant_model_service.py
…gflow into fix/image2text-to-chat-model
There was a problem hiding this comment.
♻️ Duplicate comments (1)
api/db/joint_services/tenant_model_service.py (1)
63-65:⚠️ Potential issue | 🟡 MinorLog the successful IMAGE2TEXT fallback.
The CHAT fallback flow now works, but operators still cannot tell when an
IMAGE2TEXTmodel is being resolved as CHAT.🔧 Proposed fix
+import logging import os import enumif not model_config: model_config = TenantLLMService.get_api_key(tenant_id, pure_model_name, LLMType.IMAGE2TEXT.value) + if model_config: + logging.info( + "Resolved CHAT request %r to IMAGE2TEXT model for tenant %s", + model_name, + tenant_id, + )As per coding guidelines, "Add logging for new flows".
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@api/db/joint_services/tenant_model_service.py` around lines 63 - 65, The code falls back from CHAT to IMAGE2TEXT but doesn't log that the IMAGE2TEXT model was successfully resolved as CHAT; after the line where model_config is set via TenantLLMService.get_api_key(tenant_id, pure_model_name, LLMType.IMAGE2TEXT.value) add a concise info/debug log using the module's logger (e.g., logger.info or processLogger.info) stating that IMAGE2TEXT fallback succeeded and include tenant_id, pure_model_name and which key/source was used so operators can see when IMAGE2TEXT is being resolved as CHAT (reference symbols: model_config, TenantLLMService.get_api_key, LLMType.IMAGE2TEXT, CHAT).
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Duplicate comments:
In `@api/db/joint_services/tenant_model_service.py`:
- Around line 63-65: The code falls back from CHAT to IMAGE2TEXT but doesn't log
that the IMAGE2TEXT model was successfully resolved as CHAT; after the line
where model_config is set via TenantLLMService.get_api_key(tenant_id,
pure_model_name, LLMType.IMAGE2TEXT.value) add a concise info/debug log using
the module's logger (e.g., logger.info or processLogger.info) stating that
IMAGE2TEXT fallback succeeded and include tenant_id, pure_model_name and which
key/source was used so operators can see when IMAGE2TEXT is being resolved as
CHAT (reference symbols: model_config, TenantLLMService.get_api_key,
LLMType.IMAGE2TEXT, CHAT).
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: b541d8ba-f157-455b-9b18-2798e3ead61e
📒 Files selected for processing (1)
api/db/joint_services/tenant_model_service.py
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #14331 +/- ##
=======================================
Coverage 95.30% 95.30%
=======================================
Files 10 10
Lines 703 703
Branches 112 112
=======================================
Hits 670 670
Misses 16 16
Partials 17 17 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
### What problem does this PR solve? Allow image2text models (multimodal) to be used as chat models. ### Type of change - [x] Bug Fix (non-breaking change which fixes an issue)
What problem does this PR solve?
Allow image2text models (multimodal) to be used as chat models.
Type of change