Repository navigation
Feat: display intl url for siliconflow and verify model provider without llms in json - #15550
Conversation
… fix/model-provider
📝 WalkthroughWalkthroughPrecomputes a factory-info map, ensures provider URL objects include ChangesProvider URL construction and API-key verification
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Possibly related PRs
Suggested labels
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
🧹 Nitpick comments (2)
api/apps/services/provider_api_service.py (2)
64-73: ⚡ Quick winAdd logging for the new intl URL flow.
Per coding guidelines, new flows should include logging. The intl URL feature for siliconflow is a new flow but has no logging. Consider adding a debug or info log when the intl URL is populated.
📝 Proposed logging addition
if factory_info["name"].lower() == "siliconflow": provider["url"]["intl"] = factory_info_map.get("siliconflow_intl", {}).get("url", "https://api.siliconflow.com/v1") + logging.debug(f"Added intl URL for siliconflow provider: {provider['url']['intl']}")Apply the same in both branches (all_available and tenant-configured).
As per coding guidelines: Add logging for new flows (
**/*.py).Also applies to: 90-99
🤖 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 64 - 73, The new siliconflow "intl" URL branch lacks logging; update the provider population logic (where provider, factory_info, factory_info_map and providers are used) to emit a debug/info log when you populate provider["url"]["intl"] (include the factory_info["name"] and the intl URL), and add the same logging in the other branch that builds providers (the tenant-configured branch around the other factory loop at the 90-99 area) so both flows log when the intl URL is set.
71-72: ⚡ Quick winAdd logging when falling back to hardcoded URL.
The code silently falls back to a hardcoded URL (
https://api.siliconflow.com/v1) when thesiliconflow_intlentry is missing fromFACTORY_LLM_INFOS. This could mask configuration issues. Add a warning log when the fallback is used.🔍 Proposed fix to add logging
if factory_info["name"].lower() == "siliconflow": + intl_info = factory_info_map.get("siliconflow_intl") + if not intl_info: + logging.warning("siliconflow_intl entry missing from FACTORY_LLM_INFOS, using fallback URL") - provider["url"]["intl"] = factory_info_map.get("siliconflow_intl", {}).get("url", "https://api.siliconflow.com/v1") + provider["url"]["intl"] = intl_info.get("url", "https://api.siliconflow.com/v1") if intl_info else "https://api.siliconflow.com/v1"Also applies to: 97-98
🤖 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 71 - 72, When setting provider["url"]["intl"] for factory_info["name"].lower() == "siliconflow", add a warning log if factory_info_map lacks "siliconflow_intl" (i.e., when you end up using the hardcoded "https://api.siliconflow.com/v1"); update the code around the existing expression factory_info_map.get("siliconflow_intl", {}).get("url", "https://api.siliconflow.com/v1") to check for the presence of factory_info_map.get("siliconflow_intl") and call the logger (e.g., processLogger or the module’s logger) with a warning that the fallback URL is being used and include context (factory_info["name"] and the default URL) before assigning provider["url"]["intl"]; apply the same change for the similar block around lines 97-98.
🤖 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 64-73: Extract the duplicated provider construction into a helper
function (e.g., _build_provider_dict(factory_info: dict, factory_info_map: dict)
-> dict) and call it from list_providers in both branches (the all-available
branch that builds provider from factory_info and the tenant-configured branch).
The helper should compute model_types by iterating factory_info.get("llm", [])
and collecting unique llm["model_type"] values, set "name" from
factory_info["name"], set url["default"] from factory_info.get("url", ""), and
add the "intl" url when factory_info["name"].lower() == "siliconflow" using
factory_info_map.get("siliconflow_intl", {}).get("url",
"https://api.siliconflow.com/v1"); replace the duplicated blocks (the provider
dict constructions) with calls to this helper.
- Line 53: The duplicate dictionary comprehension creates both factory_info_map
and factory_info_mapping from FACTORY_LLM_INFOS; remove the redundant
factory_info_mapping and update any references to use the existing
factory_info_map instead (search for factory_info_mapping usages in the same
function and replace them with factory_info_map), ensuring FACTORY_LLM_INFOS is
only materialized once.
---
Nitpick comments:
In `@api/apps/services/provider_api_service.py`:
- Around line 64-73: The new siliconflow "intl" URL branch lacks logging; update
the provider population logic (where provider, factory_info, factory_info_map
and providers are used) to emit a debug/info log when you populate
provider["url"]["intl"] (include the factory_info["name"] and the intl URL), and
add the same logging in the other branch that builds providers (the
tenant-configured branch around the other factory loop at the 90-99 area) so
both flows log when the intl URL is set.
- Around line 71-72: When setting provider["url"]["intl"] for
factory_info["name"].lower() == "siliconflow", add a warning log if
factory_info_map lacks "siliconflow_intl" (i.e., when you end up using the
hardcoded "https://api.siliconflow.com/v1"); update the code around the existing
expression factory_info_map.get("siliconflow_intl", {}).get("url",
"https://api.siliconflow.com/v1") to check for the presence of
factory_info_map.get("siliconflow_intl") and call the logger (e.g.,
processLogger or the module’s logger) with a warning that the fallback URL is
being used and include context (factory_info["name"] and the default URL) before
assigning provider["url"]["intl"]; apply the same change for the similar block
around lines 97-98.
🪄 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: 8ec85ab6-34c7-4591-88b7-ef3415a79030
📒 Files selected for processing (1)
api/apps/services/provider_api_service.py
|
|
||
| factory_rank_mapping = {factory["name"]: -_to_int(factory.get("rank", "500")) for factory in FACTORY_LLM_INFOS} | ||
|
|
||
| factory_info_map = {f["name"]: f for f in FACTORY_LLM_INFOS} |
There was a problem hiding this comment.
🛠️ Refactor suggestion | 🟠 Major | ⚡ Quick win
Eliminate duplicate map construction.
Both factory_info_map (line 53) and factory_info_mapping (line 81) are identical dictionary comprehensions. Reuse factory_info_map throughout the function instead of creating a duplicate.
♻️ Proposed fix to reuse the existing map
factory_info_mapping = {f["name"]: f for f in FACTORY_LLM_INFOS}
for name in factory_names:
- if name not in ["Youdao", "FastEmbed", "BAAI", "Builtin", "siliconflow_intl"] and factory_info_mapping.get(name):
- factory_info = factory_info_mapping[name]
+ if name not in ["Youdao", "FastEmbed", "BAAI", "Builtin", "siliconflow_intl"] and factory_info_map.get(name):
+ factory_info = factory_info_map[name]
model_types = sorted(set(Then remove line 81:
# List tenant-configured providers
factory_names = TenantModelProviderService.list_provider_names_by_tenant_id(tenant_id)
providers = []
- factory_info_mapping = {f["name"]: f for f in FACTORY_LLM_INFOS}
for name in factory_names:Also applies to: 81-81
🤖 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` at line 53, The duplicate
dictionary comprehension creates both factory_info_map and factory_info_mapping
from FACTORY_LLM_INFOS; remove the redundant factory_info_mapping and update any
references to use the existing factory_info_map instead (search for
factory_info_mapping usages in the same function and replace them with
factory_info_map), ensuring FACTORY_LLM_INFOS is only materialized once.
| provider = { | ||
| "model_types": model_types, | ||
| "name": factory_info["name"], | ||
| "url": { | ||
| "default": factory_info.get("url", "") | ||
| } | ||
| }) | ||
| } | ||
| if factory_info["name"].lower() == "siliconflow": | ||
| provider["url"]["intl"] = factory_info_map.get("siliconflow_intl", {}).get("url", "https://api.siliconflow.com/v1") | ||
| providers.append(provider) |
There was a problem hiding this comment.
🛠️ Refactor suggestion | 🟠 Major | ⚡ Quick win
Extract duplicated provider construction logic to a helper function.
The provider dictionary construction logic (lines 64-73 and 90-99) is duplicated in both the all-available and tenant-configured branches. Extract this to a helper function to follow DRY principles.
♻️ Proposed refactor
Add this helper function before list_providers:
def _build_provider_dict(factory_info: dict, factory_info_map: dict) -> dict:
"""Build a provider dictionary from factory info."""
model_types = sorted(set(
llm["model_type"]
for llm in factory_info.get("llm", [])
if llm.get("model_type")
))
provider = {
"model_types": model_types,
"name": factory_info["name"],
"url": {
"default": factory_info.get("url", "")
}
}
if factory_info["name"].lower() == "siliconflow":
provider["url"]["intl"] = factory_info_map.get("siliconflow_intl", {}).get("url", "https://api.siliconflow.com/v1")
return providerThen replace the duplicated blocks with:
for factory_info in FACTORY_LLM_INFOS:
if factory_info["name"] in ["Youdao", "FastEmbed", "BAAI", "Builtin", "siliconflow_intl"]:
continue
- model_types = sorted(set(
- llm["model_type"]
- for llm in factory_info.get("llm", [])
- if llm.get("model_type")
- ))
- provider = {
- "model_types": model_types,
- "name": factory_info["name"],
- "url": {
- "default": factory_info.get("url", "")
- }
- }
- if factory_info["name"].lower() == "siliconflow":
- provider["url"]["intl"] = factory_info_map.get("siliconflow_intl", {}).get("url", "https://api.siliconflow.com/v1")
- providers.append(provider)
+ providers.append(_build_provider_dict(factory_info, factory_info_map))Apply the same change in the tenant-configured branch.
Also applies to: 90-99
🤖 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 64 - 73, Extract the
duplicated provider construction into a helper function (e.g.,
_build_provider_dict(factory_info: dict, factory_info_map: dict) -> dict) and
call it from list_providers in both branches (the all-available branch that
builds provider from factory_info and the tenant-configured branch). The helper
should compute model_types by iterating factory_info.get("llm", []) and
collecting unique llm["model_type"] values, set "name" from
factory_info["name"], set url["default"] from factory_info.get("url", ""), and
add the "intl" url when factory_info["name"].lower() == "siliconflow" using
factory_info_map.get("siliconflow_intl", {}).get("url",
"https://api.siliconflow.com/v1"); replace the duplicated blocks (the provider
dict constructions) with calls to this helper.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #15550 +/- ##
=======================================
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:
|
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 `@api/apps/services/provider_api_service.py`:
- Around line 344-353: The GET call to models_url currently lacks a timeout and
can hang; wrap the aiohttp request (the async with session.get(...) as resp
block) in asyncio.wait_for using the existing timeout_seconds variable (same
pattern as other verification calls) or use aiohttp.ClientTimeout with session
to enforce the timeout; ensure you catch asyncio.TimeoutError (or the raised
exception) and return the same False, message flow while logging the timeout
appropriately; refer to models_url, timeout_seconds, and the session.get usage
to locate where to apply this change.
🪄 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: 7a86064c-e2b7-42cb-bb25-18e930a96e9d
📒 Files selected for processing (1)
api/apps/services/provider_api_service.py
| try: | ||
| async with aiohttp.ClientSession() as session: | ||
| async with session.get(models_url, headers={"Authorization": f"Bearer {api_key}"}) as resp: | ||
| if resp.status == 200: | ||
| return True, "success" | ||
| else: | ||
| return False, f"Fail to access {models_url} using this api key." | ||
| except Exception as e: | ||
| logging.error(f"Fail to access {models_url} using this api key.", exc_info=e) | ||
| return False, f"Fail to access {models_url} using this api key." |
There was a problem hiding this comment.
Missing timeout on aiohttp request.
The HTTP request to the /models endpoint has no timeout, which could cause indefinite hangs if the remote server is unresponsive. Other verification calls in this function (lines 365-368, 388, 399-402) consistently use timeout_seconds with asyncio.wait_for.
🔧 Proposed fix
+ timeout_seconds = int(os.environ.get("LLM_TIMEOUT_SECONDS", 10))
try:
- async with aiohttp.ClientSession() as session:
+ timeout = aiohttp.ClientTimeout(total=timeout_seconds)
+ async with aiohttp.ClientSession(timeout=timeout) as session:
async with session.get(models_url, headers={"Authorization": f"Bearer {api_key}"}) as resp:🤖 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 344 - 353, The GET
call to models_url currently lacks a timeout and can hang; wrap the aiohttp
request (the async with session.get(...) as resp block) in asyncio.wait_for
using the existing timeout_seconds variable (same pattern as other verification
calls) or use aiohttp.ClientTimeout with session to enforce the timeout; ensure
you catch asyncio.TimeoutError (or the raised exception) and return the same
False, message flow while logging the timeout appropriately; refer to
models_url, timeout_seconds, and the session.get usage to locate where to apply
this change.
What problem does this PR solve?
As title.
Type of change