mirror of
https://github.com/RYDE-WORK/Langchain-Chatchat.git
synced 2026-01-19 21:37:20 +08:00
model_config 中补充 oneapi 默认在线模型;/v1/models 接口支持 oneapi 平台,统一返回模型列表
This commit is contained in:
parent
82dfcd97e6
commit
1dc069fa9c
@ -118,22 +118,39 @@ MODEL_PLATFORMS = [
|
||||
],
|
||||
},
|
||||
|
||||
# {
|
||||
# "platform_name": "oneapi",
|
||||
# "platform_type": "oneapi",
|
||||
# "api_base_url": "http://127.0.0.1:3000/v1",
|
||||
# "api_key": "",
|
||||
# "api_concurrencies": 5,
|
||||
# "llm_models": [
|
||||
# "qwen-turbo",
|
||||
# "qwen-plus",
|
||||
# "chatglm_turbo",
|
||||
# "chatglm_std",
|
||||
# ],
|
||||
# "embed_models": [],
|
||||
# "image_models": [],
|
||||
# "multimodal_models": [],
|
||||
# },
|
||||
{
|
||||
"platform_name": "oneapi",
|
||||
"platform_type": "oneapi",
|
||||
"api_base_url": "http://127.0.0.1:3000/v1",
|
||||
"api_key": "sk-",
|
||||
"api_concurrencies": 5,
|
||||
"llm_models": [
|
||||
# 智谱 API
|
||||
"chatglm_pro",
|
||||
"chatglm_turbo",
|
||||
"chatglm_std",
|
||||
"chatglm_lite",
|
||||
# 千问 API
|
||||
"qwen-turbo",
|
||||
"qwen-plus",
|
||||
"qwen-max",
|
||||
"qwen-max-longcontext",
|
||||
# 千帆 API
|
||||
"ERNIE-Bot",
|
||||
"ERNIE-Bot-turbo",
|
||||
"ERNIE-Bot-4",
|
||||
# 星火 API
|
||||
"SparkDesk",
|
||||
],
|
||||
"embed_models": [
|
||||
# 千问 API
|
||||
"text-embedding-v1",
|
||||
# 千帆 API
|
||||
"Embedding-V1",
|
||||
],
|
||||
"image_models": [],
|
||||
"multimodal_models": [],
|
||||
},
|
||||
|
||||
# {
|
||||
# "platform_name": "loom",
|
||||
|
||||
@ -65,30 +65,29 @@ async def openai_request(method, body):
|
||||
|
||||
|
||||
@openai_router.get("/models")
|
||||
async def list_models() -> Dict:
|
||||
async def list_models() -> List:
|
||||
'''
|
||||
整合所有平台的模型列表。
|
||||
由于 openai sdk 不支持重名模型,对于重名模型,只返回其中响应速度最快的一个。在请求其它接口时会自动按照模型忙闲状态进行调度。
|
||||
'''
|
||||
async def task(name: str):
|
||||
async def task(name: str, config: Dict):
|
||||
try:
|
||||
client = get_OpenAIClient(name, is_async=True)
|
||||
models = await client.models.list()
|
||||
models = models.dict(exclude={"data":..., "object":...})
|
||||
for x in models:
|
||||
models[x]["platform_name"] = name
|
||||
return models
|
||||
if config.get("platform_type") == "xinference":
|
||||
models = models.dict(exclude={"data":..., "object":...})
|
||||
for x in models:
|
||||
models[x]["platform_name"] = name
|
||||
return [{**v, "id": k} for k, v in models.items()]
|
||||
elif config.get("platform_type") == "oneapi":
|
||||
return [{**x.dict(), "platform_name": name} for x in models.data]
|
||||
except Exception:
|
||||
logger.error(f"failed request to platform: {name}", exc_info=True)
|
||||
return {}
|
||||
|
||||
result = {}
|
||||
tasks = [asyncio.create_task(task(name)) for name in get_config_platforms()]
|
||||
result = []
|
||||
tasks = [asyncio.create_task(task(name, config)) for name, config in get_config_platforms().items()]
|
||||
for t in asyncio.as_completed(tasks):
|
||||
for n, v in (await t).items():
|
||||
if n not in result:
|
||||
result[n] = v
|
||||
|
||||
result += (await t)
|
||||
return result
|
||||
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user