mirror of
https://github.com/infiniflow/ragflow.git
synced 2026-07-16 20:57:21 +08:00
Feat: display intl url for siliconflow and verify model provider without llms in json (#15550)
### What problem does this PR solve? As title. ### Type of change - [x] New Feature (non-breaking change which adds functionality)
This commit is contained in:
@@ -14,6 +14,7 @@
|
||||
# limitations under the License.
|
||||
#
|
||||
import os
|
||||
import aiohttp
|
||||
import json
|
||||
import logging
|
||||
import asyncio
|
||||
@@ -50,7 +51,7 @@ def list_providers(tenant_id: str, all_available: bool = False):
|
||||
return False, []
|
||||
|
||||
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}
|
||||
if all_available:
|
||||
providers = []
|
||||
for factory_info in FACTORY_LLM_INFOS:
|
||||
@@ -61,13 +62,16 @@ def list_providers(tenant_id: str, all_available: bool = False):
|
||||
for llm in factory_info.get("llm", [])
|
||||
if llm.get("model_type")
|
||||
))
|
||||
providers.append({
|
||||
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.sort(key=lambda x: (factory_rank_mapping.get(x["name"]), x["name"]))
|
||||
return True, providers
|
||||
|
||||
@@ -84,13 +88,16 @@ def list_providers(tenant_id: str, all_available: bool = False):
|
||||
for llm in factory_info.get("llm", [])
|
||||
if llm.get("model_type")
|
||||
))
|
||||
providers.append({
|
||||
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.sort(key=lambda x: (factory_rank_mapping.get(x["name"]), x["name"]))
|
||||
return True, providers
|
||||
|
||||
@@ -326,7 +333,24 @@ async def verify_api_key(provider_name: str, api_key: str, base_url: str=None, r
|
||||
|
||||
factory_llms = factory_info[0]["llm"]
|
||||
if not factory_llms:
|
||||
return False, f"No models found for provider '{provider_name}'"
|
||||
url = base_url or factory_info[0].get("url")
|
||||
if not url:
|
||||
return False, f"No models found for provider '{provider_name}'"
|
||||
v1_index = url.find("/v1")
|
||||
if v1_index >= 0:
|
||||
models_url = url[: v1_index + 3] + "/models"
|
||||
else:
|
||||
models_url = url.rstrip("/") + "/v1/models"
|
||||
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."
|
||||
|
||||
# test if api key works
|
||||
chat_passed, embd_passed, rerank_passed = False, False, False
|
||||
|
||||
Reference in New Issue
Block a user