fix: 注入市场状态(A股交易中/已收盘 港股交易中/已收盘)防交易时段幻觉

This commit is contained in:
知微
2026-07-07 15:47:14 +08:00
parent bdd0611275
commit 073cc1a2de
+14 -3
View File
@@ -186,9 +186,20 @@ class AgentBot(ClientXMPP):
msg_type = 'groupchat' if is_group else 'chat'
sid = session_id or SESSION_ID
try:
# 注入当前日期时间,防止LLM日期幻觉
now_str = datetime.now().strftime("%Y-%m-%d %H:%M %A")
timed_content = f"[当前时间: {now_str}]\n{content}"
# 注入当前时间 + 市场状态,防止LLM日期/交易时段幻觉
now = datetime.datetime.now()
weekday = now.strftime("%A")
hour = now.hour
minute = now.minute
# 判断市场状态
is_weekday = now.weekday() < 5
if is_weekday:
ashare = "交易中" if (9 <= hour < 15) or (hour == 9 and minute >= 30) or (hour == 15 and minute == 0) else "已收盘"
hk = "交易中" if (9 <= hour < 16) or (hour == 9 and minute >= 30) or (hour == 15) else "已收盘"
else:
ashare = hk = "休市"
now_str = now.strftime("%Y-%m-%d %H:%M")
timed_content = f"[{now_str} {weekday} | A股{ashare} 港股{hk}]\n{content}"
payload = json.dumps({
"model": "hermes-agent",
"messages": [{"role": "user", "content": timed_content}]