mirror of
https://github.com/RYDE-WORK/Langchain-Chatchat.git
synced 2026-01-25 08:13:30 +08:00
* 修复Azure 不设置Max token的bug * 重写agent 1. 修改Agent实现方式,支持多参数,仅剩 ChatGLM3-6b和 OpenAI GPT4 支持,剩余模型将在暂时缺席Agent功能 2. 删除agent_chat 集成到llm_chat中 3. 重写大部分工具,适应新Agent * 更新架构 * 删除web_chat,自动融合 * 移除所有聊天,都变成Agent控制 * 更新配置文件 * 更新配置模板和提示词 * 更改参数选择bug
59 lines
2.0 KiB
Python
59 lines
2.0 KiB
Python
import sys
|
|
from pathlib import Path
|
|
root_path = Path(__file__).parent.parent
|
|
sys.path.append(str(root_path))
|
|
|
|
from configs import ONLINE_LLM_MODEL
|
|
from server.model_workers.base import *
|
|
from server.utils import get_model_worker_config, list_config_llm_models
|
|
from pprint import pprint
|
|
import pytest
|
|
|
|
|
|
workers = []
|
|
for x in list_config_llm_models()["online"]:
|
|
if x in ONLINE_LLM_MODEL and x not in workers:
|
|
workers.append(x)
|
|
print(f"all workers to test: {workers}")
|
|
|
|
# workers = ["fangzhou-api"]
|
|
|
|
|
|
@pytest.mark.parametrize("worker", workers)
|
|
def test_chat(worker):
|
|
params = ApiChatParams(
|
|
messages = [
|
|
{"role": "user", "content": "你是谁"},
|
|
],
|
|
)
|
|
print(f"\nchat with {worker} \n")
|
|
|
|
if worker_class := get_model_worker_config(worker).get("worker_class"):
|
|
for x in worker_class().do_chat(params):
|
|
pprint(x)
|
|
assert isinstance(x, dict)
|
|
assert x["error_code"] == 0
|
|
|
|
|
|
@pytest.mark.parametrize("worker", workers)
|
|
def test_embeddings(worker):
|
|
params = ApiEmbeddingsParams(
|
|
texts = [
|
|
"LangChain-Chatchat (原 Langchain-ChatGLM): 基于 Langchain 与 ChatGLM 等大语言模型的本地知识库问答应用实现。",
|
|
"一种利用 langchain 思想实现的基于本地知识库的问答应用,目标期望建立一套对中文场景与开源模型支持友好、可离线运行的知识库问答解决方案。",
|
|
]
|
|
)
|
|
|
|
if worker_class := get_model_worker_config(worker).get("worker_class"):
|
|
if worker_class.can_embedding():
|
|
print(f"\embeddings with {worker} \n")
|
|
resp = worker_class().do_embeddings(params)
|
|
|
|
pprint(resp, depth=2)
|
|
assert resp["code"] == 200
|
|
assert "data" in resp
|
|
embeddings = resp["data"]
|
|
assert isinstance(embeddings, list) and len(embeddings) > 0
|
|
assert isinstance(embeddings[0], list) and len(embeddings[0]) > 0
|
|
assert isinstance(embeddings[0][0], float)
|
|
print("向量长度:", len(embeddings[0])) |