mirror of
https://github.com/RYDE-WORK/Langchain-Chatchat.git
synced 2026-01-19 21:37:20 +08:00
* update ApiRequest: 删除no_remote_api本地调用模式;支持同步/异步调用 * 实现API和WEBUI的分离: - API运行服务器上的配置通过/llm_model/get_model_config、/server/configs接口提供,WEBUI运行机器上的配置项仅作为代码内部默认值使用 - 服务器可用的搜索引擎通过/server/list_search_engines提供 - WEBUI可选LLM列表中只列出在FSCHAT_MODEL_WORKERS中配置的模型 - 修改WEBUI中默认LLM_MODEL获取方式,改为从api端读取 - 删除knowledge_base_chat中`local_doc_url`参数 其它修改: - 删除多余的kb_config.py.exmaple(名称错误) - server_config中默认关闭vllm - server_config中默认注释除智谱AI之外的在线模型 - 修改requests从系统获取的代理,避免model worker注册错误 * 修正: - api.list_config_models返回模型原始配置 - api.list_config_models和api.get_model_config中过滤online api模型的敏感信息 - 将GPT等直接访问的模型列入WEBUI可选模型列表 其它: - 指定langchain==0.3.313, fschat==0.2.30, langchain-experimental==0.0.30
72 lines
2.1 KiB
Python
72 lines
2.1 KiB
Python
import requests
|
||
import json
|
||
import sys
|
||
from pathlib import Path
|
||
|
||
root_path = Path(__file__).parent.parent.parent
|
||
sys.path.append(str(root_path))
|
||
from configs.server_config import FSCHAT_MODEL_WORKERS
|
||
from configs.model_config import LLM_MODEL
|
||
from server.utils import api_address, get_model_worker_config
|
||
|
||
from pprint import pprint
|
||
import random
|
||
from typing import List
|
||
|
||
|
||
def get_configured_models() -> List[str]:
|
||
model_workers = list(FSCHAT_MODEL_WORKERS)
|
||
if "default" in model_workers:
|
||
model_workers.remove("default")
|
||
return model_workers
|
||
|
||
|
||
api_base_url = api_address()
|
||
|
||
|
||
def get_running_models(api="/llm_model/list_models"):
|
||
url = api_base_url + api
|
||
r = requests.post(url)
|
||
if r.status_code == 200:
|
||
return r.json()["data"]
|
||
return []
|
||
|
||
|
||
def test_running_models(api="/llm_model/list_running_models"):
|
||
url = api_base_url + api
|
||
r = requests.post(url)
|
||
assert r.status_code == 200
|
||
print("\n获取当前正在运行的模型列表:")
|
||
pprint(r.json())
|
||
assert isinstance(r.json()["data"], list)
|
||
assert len(r.json()["data"]) > 0
|
||
|
||
|
||
# 不建议使用stop_model功能。按现在的实现,停止了就只能手动再启动
|
||
# def test_stop_model(api="/llm_model/stop"):
|
||
# url = api_base_url + api
|
||
# r = requests.post(url, json={""})
|
||
|
||
|
||
def test_change_model(api="/llm_model/change_model"):
|
||
url = api_base_url + api
|
||
|
||
running_models = get_running_models()
|
||
assert len(running_models) > 0
|
||
|
||
model_workers = get_configured_models()
|
||
|
||
availabel_new_models = list(set(model_workers) - set(running_models))
|
||
assert len(availabel_new_models) > 0
|
||
print(availabel_new_models)
|
||
|
||
local_models = [x for x in running_models if not get_model_worker_config(x).get("online_api")]
|
||
model_name = random.choice(local_models)
|
||
new_model_name = random.choice(availabel_new_models)
|
||
print(f"\n尝试将模型从 {model_name} 切换到 {new_model_name}")
|
||
r = requests.post(url, json={"model_name": model_name, "new_model_name": new_model_name})
|
||
assert r.status_code == 200
|
||
|
||
running_models = get_running_models()
|
||
assert new_model_name in running_models
|