Repository navigation
Fix: verify remote model when model_list in argument and factory_llms is empty - #17364
Conversation
📝 WalkthroughWalkthroughChangesProvider model discovery
Estimated code review effort: 2 (Simple) | ~10 minutes Suggested reviewers: Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 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 |
wangq8
left a comment
There was a problem hiding this comment.
Thanks for this fix! The approach makes sense — when factory_llms is empty, falling back to dynamically discovering models from the remote provider is much better than immediately returning an error. This is especially useful for providers that don't pre-configure their model list in factory_llms.
What I checked:
- The
ModelMeta[provider_name](api_key, model_base_url).get_model_list()pattern is already established in the codebase (used inshow_provider_llmaround line 213), so this is consistent. - The constructed
factory_llmsentries (model_type/llm_name) match the format consumed by the verification loop below. - The
try/exceptguard ensures this fallback is non-breaking — if the remote call fails for any reason, it falls through to the original error return.
One minor observation (non-blocking): The except Exception: pass is quite broad. In a future iteration, it might be worth logging the exception at debug level so that intermittent network errors or API issues can be traced. But as a fallback, this is perfectly fine.
LGTM! ✅
There was a problem hiding this comment.
Actionable comments posted: 2
🧹 Nitpick comments (1)
api/apps/services/provider_api_service.py (1)
671-687: 🎯 Functional Correctness | 🔵 Trivial | ⚡ Quick winAdd regression coverage for the empty-list fallback.
Mock
ModelMetaand verify thatmodel_info=[]discovers remote models, mapsname/model_typesintofactory_llms, and preserves the “No models found” result when discovery returns no usable models or fails.🤖 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/provider_api_service.py` around lines 671 - 687, Extend regression tests for the provider model-discovery flow around ModelMeta and the model_info fallback: mock ModelMeta so model_info=[] triggers remote discovery, verify remote model name/model_types are mapped into factory_llms, and cover both empty/unusable discovery results and discovery exceptions returning the existing “No models found” response.Source: Coding guidelines
🤖 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/provider_api_service.py`:
- Around line 684-685: Update the exception handling in the provider discovery
flow around the broad `except Exception` to catch only expected
discovery-related errors, log the provider and exception details without
including API keys, and re-raise unexpected exceptions instead of silently
returning “No models found.”
- Around line 671-674: Update the remote discovery call in verify_api_key around
ModelMeta[provider_name](...).get_model_list() to enforce an explicit bounded
timeout for each model-list request, using the existing LLM_TIMEOUT_SECONDS
configuration or passing it through to the provider implementation; ensure
stalled aiohttp discovery cannot exceed the API-key verification timeout.
---
Nitpick comments:
In `@api/apps/services/provider_api_service.py`:
- Around line 671-687: Extend regression tests for the provider model-discovery
flow around ModelMeta and the model_info fallback: mock ModelMeta so
model_info=[] triggers remote discovery, verify remote model name/model_types
are mapped into factory_llms, and cover both empty/unusable discovery results
and discovery exceptions returning the existing “No models found” response.
🪄 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 Plus
Run ID: 2b09ca82-e7a4-462b-a674-65905efdd9f9
📒 Files selected for processing (1)
api/apps/services/provider_api_service.py
| model_base_url = base_url or factory_info[0].get("url", "") | ||
| try: | ||
| if provider_name in ModelMeta: | ||
| remote_models = await ModelMeta[provider_name](api_key, model_base_url).get_model_list() |
There was a problem hiding this comment.
🩺 Stability & Availability | 🟠 Major | ⚡ Quick win
🧩 Analysis chain
🏁 Script executed:
#!/bin/bash
set -euo pipefail
echo "Files matching provider_api_service.py:"
fd -a 'provider_api_service\.py$' . || true
FILE="$(fd 'provider_api_service\.py$' . | head -n 1 || true)"
if [ -z "${FILE:-}" ]; then
echo "No provider_api_service.py found"
exit 0
fi
echo "Selected: $FILE"
wc -l "$FILE"
echo "--- outline around relevant symbols ---"
ast-grep outline "$FILE" --match ModelMeta --view expanded || true
echo "--- lines 630-720 ---"
sed -n '630,720p' "$FILE"
echo "--- search get_model_list / ModelMeta definitions ---"
rg -n "class ModelMeta|get_model_list|verify_api_key|_run_verification|aiohttp|timeout" -S .Repository: infiniflow/ragflow
Length of output: 50375
🏁 Script executed:
#!/bin/bash
set -euo pipefail
FILE="api/apps/services/provider_api_service.py"
echo "--- provider_api_service.py lines 630-720 ---"
sed -n '630,720p' "$FILE" | cat -n -v
echo "--- provider_api_service.py imports / verify_api_key definition ---"
rg -n "from common.connection_utils import timeout|def verify_api_key|async def verify_api_key|_run_verification|`@timeout`" "$FILE"
echo "--- ProviderMeta class(s) and get_model_list implementations ---"
python3 - <<'PY'
from pathlib import Path
import ast
for path in Path('.').rglob('*.py'):
if any(part in {'venv', '.git', '__pycache__'} for part in path.parts):
continue
try:
txt = path.read_text(encoding='utf-8', errors='ignore')
except Exception:
continue
if 'class ProviderMeta' in txt or 'get_model_list' in txt:
try:
tree = ast.parse(txt)
except SyntaxError:
continue
for node in ast.walk(tree):
if not isinstance(node, ast.ClassDef):
continue
if node.name in {'ProviderMeta', 'LocalAI', 'FunASR'} or any(n == 'get_model_list' for n in [node.name]):
print(f"FILE {path}:{node.lineno}")
print(' ', node.name)
PY
echo "--- focused ModelMeta get_model_list implementations ---"
rg -n "class ModelMeta|def get_model_list|async def get_model_list|async def _get_model_list|ClientSession|aiohttp" api tests -S --max-count 200Repository: infiniflow/ragflow
Length of output: 10703
🌐 Web query:
aiohttp.ClientSession get timeout default None connect_timeout default aiohttp documentation
💡 Result:
In aiohttp, timeout settings are managed via the ClientTimeout data structure [1][2]. When not explicitly provided, the default timeout configuration used by ClientSession is [1][2]: aiohttp.ClientTimeout(total=300, connect=None, sock_connect=None, sock_read=None, ceil_threshold=5) Key default values include: total: 300 seconds (5 minutes) [1][2]. This is the maximum time for the entire operation [1][2]. connect: None [1][2]. Note that while the ClientTimeout object defaults to None for connect, some documentation summaries note a 30-second socket connect timeout in the broader context of the session's default behavior [3][4]. The ClientTimeout structure itself maintains None for connect and sock_connect by default [1][2][5]. sock_connect: None [1][2]. sock_read: None [1][2]. You can override these defaults by passing a custom ClientTimeout instance to the ClientSession constructor [1][3] or directly to individual request methods like ClientSession.get [1][2]. If you pass a float to the timeout parameter (for backward compatibility), it is interpreted as the total timeout in seconds [3][4]. Any field set to None or 0 disables that specific timeout check [1][2].
Citations:
- 1: https://docs.aiohttp.org/en/latest/client_quickstart.html
- 2: http://docs.aiohttp.org/en/stable/client_quickstart.html
- 3: https://docs.aiohttp.org/en/latest/client%5Freference.html
- 4: http://docs.aiohttp.org/en/stable/client_reference.html
- 5: https://docs.aiohttp.org/en/latest/%5Fmodules/aiohttp/client%5Freqrep.html
Bound the remote model discovery request.
Line 684 starts remote model discovery before _run_verification can apply LLM_TIMEOUT_SECONDS; ModelMeta.get_model_list() uses aiohttp without an explicit per-model timeout, so a provider that accepts the connection but stalls can make verify_api_key wait beyond the stated API-key verification timeout. Add a bounded discovery timeout there or pass one through this call.
🤖 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/provider_api_service.py` around lines 671 - 674, Update the
remote discovery call in verify_api_key around
ModelMeta[provider_name](...).get_model_list() to enforce an explicit bounded
timeout for each model-list request, using the existing LLM_TIMEOUT_SECONDS
configuration or passing it through to the provider implementation; ensure
stalled aiohttp discovery cannot exceed the API-key verification timeout.
| except Exception: | ||
| pass |
There was a problem hiding this comment.
🩺 Stability & Availability | 🟠 Major | ⚡ Quick win
Do not silently swallow discovery failures.
This catches every exception and converts outages, authentication errors, malformed responses, and programming bugs into a misleading “No models found” result. Catch expected discovery errors, log the provider and exception without exposing the API key, and let unexpected bugs surface. As per coding guidelines, **/*.py: Add logging for new flows.
🧰 Tools
🪛 Ruff (0.15.21)
[error] 684-685: try-except-pass detected, consider logging the exception
(S110)
[warning] 684-684: Do not catch blind exception: Exception
(BLE001)
🤖 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/provider_api_service.py` around lines 684 - 685, Update the
exception handling in the provider discovery flow around the broad `except
Exception` to catch only expected discovery-related errors, log the provider and
exception details without including API keys, and re-raise unexpected exceptions
instead of silently returning “No models found.”
Sources: Coding guidelines, Linters/SAST tools
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #17364 +/- ##
=======================================
Coverage 90.65% 90.65%
=======================================
Files 10 10
Lines 717 717
Branches 118 118
=======================================
Hits 650 650
Misses 39 39
Partials 28 28 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
…er type fail Two remaining verify-path fixes after infiniflow#17158 (api_base -> base_url rename) and infiniflow#17364/infiniflow#17397 (empty-catalog remote model discovery) landed on main: - useVerifyProvider now accepts a modelInfoRef carrying the models selected in the List-models picker (not registered as form fields) and folds them into the verify payload, so local/compatible providers no longer verify against an empty model_info. - _record_model_verify_failure records FAIL without overwriting a prior SUCCESS for the same llm_name. model_info is unrolled into one factory_llms entry per capability type, so a later type failure must not erase an earlier successful capability result. - Wrap Embedding/Chat model construction in try/except so an init failure is recorded as a per-model FAIL instead of aborting the whole verify. Co-authored-by: Cursor <[email protected]>
Summary
As title.