Skip to content

Fix: allow use image2text as chat model - #14331

Merged
wangq8 merged 8 commits into
infiniflow:mainfrom
Lynn-Inf:fix/image2text-to-chat-model
Apr 24, 2026
Merged

wangq8 merged 8 commits into
infiniflow:mainfrom
Lynn-Inf:fix/image2text-to-chat-model

Conversation

@Lynn-Inf

Copy link
Copy Markdown
Contributor

What problem does this PR solve?

Allow image2text models (multimodal) to be used as chat models.

Type of change

  • Bug Fix (non-breaking change which fixes an issue)

@dosubot dosubot Bot added the size:XS This PR changes 0-9 lines, ignoring generated files. label Apr 23, 2026
@coderabbitai

coderabbitai Bot commented Apr 23, 2026 •

Copy link
Copy Markdown
Contributor
📝 Walkthrough

Walkthrough

get_model_config_by_type_and_name now adds a fallback for LLMType.CHAT: if tenant lookup fails it will try resolving by pure_model_name first as CHAT, then as IMAGE2TEXT; the final validation permits an IMAGE2TEXT resolution when the original request was CHAT while other type mismatches still raise.

Changes

Cohort / File(s) Summary
Model configuration lookup
api/db/joint_services/tenant_model_service.py
Updated get_model_config_by_type_and_name to: try pure_model_name for CHAT, fall back to IMAGE2TEXT if CHAT not found, and relax final type validation to accept IMAGE2TEXT results when CHAT was requested; other type mismatches still error.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Possibly related PRs

  • Fix: different llm in chat #14162: Adjusts dialog service usage of get_model_config_by_type_and_name and reorders llm_id vs tenant_llm_id precedence; closely related to the lookup behavior changed here.

Poem

🐰 I hop through configs, nimble and spry,
If CHAT hides away, IMAGE2TEXT I try.
No angry errors, just a gentle fall-through,
One soft hop later — a model found true! ✨

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title 'Fix: allow use image2text as chat model' directly and clearly describes the main change in the pull request.
Description check ✅ Passed The description covers the required template sections with a clear problem statement and correct type of change classification.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ 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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@Lynn-Inf Lynn-Inf added 🐞 bug Something isn't working, pull request that fix bug. ci Continue Integration labels Apr 23, 2026
@Lynn-Inf
Lynn-Inf marked this pull request as draft April 23, 2026 11:11
@Lynn-Inf
Lynn-Inf marked this pull request as ready for review April 23, 2026 11:11

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

📥 Commits

Reviewing files that changed from the base of the PR and between d4fa573 and 2fc1010.

📒 Files selected for processing (1)
  • api/db/joint_services/tenant_model_service.py

@dosubot dosubot Bot added size:S This PR changes 10-29 lines, ignoring generated files. and removed size:XS This PR changes 0-9 lines, ignoring generated files. labels Apr 23, 2026

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

♻️ Duplicate comments (1)
api/db/joint_services/tenant_model_service.py (1)

63-65: ⚠️ Potential issue | 🟡 Minor

Log the successful IMAGE2TEXT fallback.

The CHAT fallback flow now works, but operators still cannot tell when an IMAGE2TEXT model is being resolved as CHAT.

🔧 Proposed fix
+import logging
 import os
 import enum
             if 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

📥 Commits

Reviewing files that changed from the base of the PR and between 2fc1010 and f2f99c3.

📒 Files selected for processing (1)
  • api/db/joint_services/tenant_model_service.py

@codecov

codecov Bot commented Apr 23, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 95.30%. Comparing base (199fbce) to head (bd2fcdd).
⚠️ Report is 6 commits behind head on main.

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.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@Lynn-Inf Lynn-Inf mentioned this pull request Apr 23, 2026
4 tasks done
@wangq8
wangq8 requested review from Magicbook1108 and wangq8 April 24, 2026 09:51

@Magicbook1108 Magicbook1108 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@wangq8
wangq8 merged commit beb2406 into infiniflow:main Apr 24, 2026
1 check passed
xugangqiang pushed a commit to xugangqiang/ragflow that referenced this pull request Apr 24, 2026
### 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)
@dosubot dosubot Bot mentioned this pull request Apr 28, 2026
4 tasks done
@dosubot dosubot Bot mentioned this pull request May 14, 2026
4 tasks done
@coderabbitai coderabbitai Bot mentioned this pull request May 22, 2026
1 task done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

🐞 bug Something isn't working, pull request that fix bug. ci Continue Integration size:S This PR changes 10-29 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants