mirror of
https://github.com/RYDE-WORK/Langchain-Chatchat.git
synced 2026-01-19 21:37:20 +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
88 lines
2.1 KiB
Python
88 lines
2.1 KiB
Python
import requests
|
|
import json
|
|
import sys
|
|
from pathlib import Path
|
|
|
|
sys.path.append(str(Path(__file__).parent.parent.parent))
|
|
from configs import BING_SUBSCRIPTION_KEY
|
|
from server.utils import api_address
|
|
|
|
from pprint import pprint
|
|
|
|
|
|
api_base_url = api_address()
|
|
|
|
|
|
def dump_input(d, title):
|
|
print("\n")
|
|
print("=" * 30 + title + " input " + "="*30)
|
|
pprint(d)
|
|
|
|
|
|
def dump_output(r, title):
|
|
print("\n")
|
|
print("=" * 30 + title + " output" + "="*30)
|
|
for line in r.iter_content(None, decode_unicode=True):
|
|
print(line, end="", flush=True)
|
|
|
|
|
|
headers = {
|
|
'accept': 'application/json',
|
|
'Content-Type': 'application/json',
|
|
}
|
|
|
|
data = {
|
|
"query": "请用100字左右的文字介绍自己",
|
|
"history": [
|
|
{
|
|
"role": "user",
|
|
"content": "你好"
|
|
},
|
|
{
|
|
"role": "assistant",
|
|
"content": "你好,我是人工智能大模型"
|
|
}
|
|
],
|
|
"stream": True,
|
|
"temperature": 0.7,
|
|
}
|
|
|
|
|
|
def test_chat_chat(api="/chat/chat"):
|
|
url = f"{api_base_url}{api}"
|
|
dump_input(data, api)
|
|
response = requests.post(url, headers=headers, json=data, stream=True)
|
|
dump_output(response, api)
|
|
assert response.status_code == 200
|
|
|
|
|
|
def test_knowledge_chat(api="/chat/knowledge_base_chat"):
|
|
url = f"{api_base_url}{api}"
|
|
data = {
|
|
"query": "如何提问以获得高质量答案",
|
|
"knowledge_base_name": "samples",
|
|
"history": [
|
|
{
|
|
"role": "user",
|
|
"content": "你好"
|
|
},
|
|
{
|
|
"role": "assistant",
|
|
"content": "你好,我是 ChatGLM"
|
|
}
|
|
],
|
|
"stream": True
|
|
}
|
|
dump_input(data, api)
|
|
response = requests.post(url, headers=headers, json=data, stream=True)
|
|
print("\n")
|
|
print("=" * 30 + api + " output" + "="*30)
|
|
for line in response.iter_content(None, decode_unicode=True):
|
|
data = json.loads(line[6:])
|
|
if "answer" in data:
|
|
print(data["answer"], end="", flush=True)
|
|
pprint(data)
|
|
assert "docs" in data and len(data["docs"]) > 0
|
|
assert response.status_code == 200
|
|
|