- Added a new visitor chat API endpoint (`/api/chat/visitor`) to allow unauthenticated users to engage in conversations without requiring customer data. - Introduced a visitor context dependency to manage visitor interactions seamlessly. - Enhanced the chat API to support explicit session termination and improved response handling for customer service interactions. - Updated the database configuration to include Redis client support for caching visitor data. - Added a new customer note repository to persist user notes independently of the L1 profile slots. This update significantly improves the customer service experience by enabling visitor interactions and ensuring efficient data handling for both registered and unregistered users.
37 lines
1.2 KiB
Python
37 lines
1.2 KiB
Python
"""游客接口端到端测试。"""
|
|
import json
|
|
import urllib.request
|
|
|
|
URL = "http://127.0.0.1:8000/api/chat/visitor"
|
|
|
|
CASES = [
|
|
("产品咨询", "R3中风险产品有哪些?"),
|
|
("违规-推荐", "推荐一只稳赚的基金"),
|
|
("闲聊", "你好,你是谁?"),
|
|
("FAQ", "开户需要准备哪些材料?"),
|
|
("政策", "投资者适当性匹配是怎么规定的?"),
|
|
]
|
|
|
|
|
|
def call(message, session_id=None):
|
|
body = json.dumps({"message": message, "session_id": session_id}).encode("utf-8")
|
|
req = urllib.request.Request(
|
|
URL, data=body, headers={"Content-Type": "application/json"}, method="POST"
|
|
)
|
|
with urllib.request.urlopen(req, timeout=90) as resp:
|
|
return json.loads(resp.read().decode("utf-8"))
|
|
|
|
|
|
for name, msg in CASES:
|
|
print(f"\n{'=' * 60}")
|
|
print(f"【{name}】用户:{msg}")
|
|
try:
|
|
r = call(msg)
|
|
data = r.get("data", {})
|
|
print(f"意图:{data.get('intent')}")
|
|
print(f"转人工:{data.get('transfer_to_human')}")
|
|
print(f"风险提示:{data.get('has_disclaimer')}")
|
|
print(f"回复:{data.get('reply')}")
|
|
except Exception as e:
|
|
print(f"请求失败:{e}")
|