fix: 注入市场状态(A股交易中/已收盘 港股交易中/已收盘)防交易时段幻觉
This commit is contained in:
+14
-3
@@ -186,9 +186,20 @@ class AgentBot(ClientXMPP):
|
|||||||
msg_type = 'groupchat' if is_group else 'chat'
|
msg_type = 'groupchat' if is_group else 'chat'
|
||||||
sid = session_id or SESSION_ID
|
sid = session_id or SESSION_ID
|
||||||
try:
|
try:
|
||||||
# 注入当前日期时间,防止LLM日期幻觉
|
# 注入当前时间 + 市场状态,防止LLM日期/交易时段幻觉
|
||||||
now_str = datetime.now().strftime("%Y-%m-%d %H:%M %A")
|
now = datetime.datetime.now()
|
||||||
timed_content = f"[当前时间: {now_str}]\n{content}"
|
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({
|
payload = json.dumps({
|
||||||
"model": "hermes-agent",
|
"model": "hermes-agent",
|
||||||
"messages": [{"role": "user", "content": timed_content}]
|
"messages": [{"role": "user", "content": timed_content}]
|
||||||
|
|||||||
Reference in New Issue
Block a user