Skip to content

Feat: display intl url for siliconflow and verify model provider without llms in json - #15550

Merged
wangq8 merged 25 commits into
infiniflow:mainfrom
Lynn-Inf:fix/model-provider
Jun 3, 2026
Merged

wangq8 merged 25 commits into
infiniflow:mainfrom
Lynn-Inf:fix/model-provider

Conversation

@Lynn-Inf

@Lynn-Inf Lynn-Inf commented Jun 3, 2026

Copy link
Copy Markdown
Contributor

What problem does this PR solve?

As title.

Type of change

  • New Feature (non-breaking change which adds functionality)

@dosubot dosubot Bot added size:S This PR changes 10-29 lines, ignoring generated files. 💞 feature Feature request, pull request that fullfill a new feature. labels Jun 3, 2026
@coderabbitai

coderabbitai Bot commented Jun 3, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

Precomputes a factory-info map, ensures provider URL objects include url.default and conditional url.intl for siliconflow, and verifies API keys by calling the provider /models endpoint using aiohttp, returning success only on HTTP 200.

Changes

Provider URL construction and API-key verification

Layer / File(s) Summary
Factory info map construction
api/apps/services/provider_api_service.py
Precompute factory_info_map mapping factory names to their FACTORY_LLM_INFOS entries for reuse when building provider URL fields.
Provider listing URL population
api/apps/services/provider_api_service.py
Both all-available and tenant-configured provider listing paths now populate url.default and, when the factory/provider name is siliconflow, set url.intl using the factory lookup (with a fallback URL).
API-key verification via /models endpoint
api/apps/services/provider_api_service.py
Adds aiohttp import and verifies API keys by deriving a /models endpoint from the provider/factory base URL and performing an authenticated GET; returns success only for HTTP 200 responses and logs/errors otherwise.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

  • infiniflow/ragflow#15517: Both PRs modify list_providers logic to handle siliconflow/siliconflow_intl via FACTORY_LLM_INFOS-based factory mapping in provider object construction.

Suggested labels

size:M

Poem

🐰 A rabbit hops through factory maps so fine,
It tucks default URLs in every line,
For Siliconflow it whispers an intl way,
Then knocks on /models to check the key today —
Hooray, the providers now behave in kind!

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Description check ⚠️ Warning The PR description lacks substantive explanation; it only says 'As title' instead of providing background context about the problem being solved. Replace 'As title' with a detailed explanation of why displaying the international URL for siliconflow is needed and how it benefits users.
✅ Passed checks (4 passed)
Check name Status Explanation
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
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.
Title check ✅ Passed The title partially aligns with the changeset. It mentions displaying intl url for siliconflow, which is covered, but incompletely describes the verify_api_key addition without llms in json.

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

@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

🧹 Nitpick comments (2)
api/apps/services/provider_api_service.py (2)

64-73: ⚡ Quick win

Add 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 win

Add logging when falling back to hardcoded URL.

The code silently falls back to a hardcoded URL (https://api.siliconflow.com/v1) when the siliconflow_intl entry is missing from FACTORY_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

📥 Commits

Reviewing files that changed from the base of the PR and between ff59714 and 811929c.

📒 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}

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.

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

Comment on lines +64 to +73
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)

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.

🛠️ 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 provider

Then 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.

@Lynn-Inf Lynn-Inf added the ci Continue Integration label Jun 3, 2026
@Lynn-Inf
Lynn-Inf marked this pull request as draft June 3, 2026 03:36
@Lynn-Inf
Lynn-Inf marked this pull request as ready for review June 3, 2026 03:36
@codecov

codecov Bot commented Jun 3, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 93.16%. Comparing base (ff59714) to head (09de926).
⚠️ Report is 3 commits behind head on main.

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.
📢 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.

@dosubot dosubot Bot added size:M This PR changes 30-99 lines, ignoring generated files. and removed size:S This PR changes 10-29 lines, ignoring generated files. labels Jun 3, 2026
@Lynn-Inf Lynn-Inf changed the title Feat: display intl url for siliconflow Feat: display intl url for siliconflow and verify model provider without llms in json Jun 3, 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.

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

📥 Commits

Reviewing files that changed from the base of the PR and between 811929c and 39b2f17.

📒 Files selected for processing (1)
  • api/apps/services/provider_api_service.py

Comment on lines +344 to +353
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."

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.

⚠️ Potential issue | 🟠 Major | ⚡ Quick win

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.

@wangq8
wangq8 merged commit ac3964b into infiniflow:main Jun 3, 2026
1 check passed
@coderabbitai coderabbitai Bot mentioned this pull request Jun 9, 2026
1 task done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ci Continue Integration 💞 feature Feature request, pull request that fullfill a new feature. size:M This PR changes 30-99 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants