fix: 修改prompt错误
This commit is contained in:
@@ -215,3 +215,24 @@
|
||||
2022-12-08 18:31:58,165 [INFO] (gateway.py:136)ws_identify [botpy] 鉴权中...
|
||||
2022-12-08 18:31:58,269 [INFO] (gateway.py:80)on_message [botpy] 机器人「SoGPT-测试中」启动成功!
|
||||
2022-12-08 18:31:58,270 [INFO] (gateway.py:217)_send_heart [botpy] 心跳维持启动...
|
||||
2022-12-08 19:01:58,099 [INFO] (gateway.py:54)on_closed [botpy] 关闭, 返回码: 4009, 返回信息: Session timed out
|
||||
2022-12-08 19:02:03,110 [INFO] (connection.py:59)multi_run [botpy] 最大并发连接数: 1, 启动会话数: 1
|
||||
2022-12-08 19:02:03,111 [INFO] (client.py:236)bot_connect [botpy] 会话启动中...
|
||||
2022-12-08 19:02:03,111 [INFO] (gateway.py:110)ws_connect [botpy] 启动中...
|
||||
2022-12-08 19:02:03,314 [INFO] (gateway.py:169)ws_resume [botpy] 重连启动...
|
||||
2022-12-08 19:02:03,381 [INFO] (gateway.py:85)on_message [botpy] 机器人重连成功!
|
||||
2022-12-08 19:02:03,382 [INFO] (gateway.py:217)_send_heart [botpy] 心跳维持启动...
|
||||
2022-12-08 19:32:03,274 [INFO] (gateway.py:54)on_closed [botpy] 关闭, 返回码: 4009, 返回信息: Session timed out
|
||||
2022-12-08 19:32:08,271 [INFO] (connection.py:59)multi_run [botpy] 最大并发连接数: 1, 启动会话数: 1
|
||||
2022-12-08 19:32:08,272 [INFO] (client.py:236)bot_connect [botpy] 会话启动中...
|
||||
2022-12-08 19:32:08,272 [INFO] (gateway.py:110)ws_connect [botpy] 启动中...
|
||||
2022-12-08 19:32:08,534 [INFO] (gateway.py:169)ws_resume [botpy] 重连启动...
|
||||
2022-12-08 19:32:08,604 [INFO] (gateway.py:85)on_message [botpy] 机器人重连成功!
|
||||
2022-12-08 19:32:08,605 [INFO] (gateway.py:217)_send_heart [botpy] 心跳维持启动...
|
||||
2022-12-08 20:02:08,495 [INFO] (gateway.py:54)on_closed [botpy] 关闭, 返回码: 4009, 返回信息: Session timed out
|
||||
2022-12-08 20:02:13,497 [INFO] (connection.py:59)multi_run [botpy] 最大并发连接数: 1, 启动会话数: 1
|
||||
2022-12-08 20:02:13,497 [INFO] (client.py:236)bot_connect [botpy] 会话启动中...
|
||||
2022-12-08 20:02:13,498 [INFO] (gateway.py:110)ws_connect [botpy] 启动中...
|
||||
2022-12-08 20:02:13,797 [INFO] (gateway.py:169)ws_resume [botpy] 重连启动...
|
||||
2022-12-08 20:02:13,914 [INFO] (gateway.py:85)on_message [botpy] 机器人重连成功!
|
||||
2022-12-08 20:02:13,915 [INFO] (gateway.py:217)_send_heart [botpy] 心跳维持启动...
|
||||
|
||||
+16
-20
@@ -19,26 +19,22 @@ class botClient(botpy.Client):
|
||||
if result:
|
||||
qq_msg = result.group(1).strip()
|
||||
print(qq_msg)
|
||||
# 检测@头,返回对应session
|
||||
pattern0 = r"<@!\d+>"
|
||||
result0 = re.search(pattern0, message.content)
|
||||
if result0:
|
||||
session_id = result0.group(0)
|
||||
if session_id in session_dict:
|
||||
print("旧会话 "+session_id)
|
||||
chatgpt_res =await chatgpt.chat(session_dict[session_id]+' '+qq_msg)
|
||||
|
||||
chatgpt_res = chatgpt_res.strip()
|
||||
session_dict[session_id] = session_dict[session_id] + ' ' + qq_msg
|
||||
await message.reply(content=f"[ChatGPT]{chatgpt_res}")
|
||||
else:
|
||||
print("新会话 "+session_id)
|
||||
# new_session = chatgpt.newSession()
|
||||
session_dict[session_id] = qq_msg
|
||||
|
||||
chatgpt_res = await chatgpt.chat(qq_msg)
|
||||
chatgpt_res = chatgpt_res.strip()
|
||||
await message.reply(content=f"[ChatGPT]{chatgpt_res}")
|
||||
# 检测@头,返回对应缓存的prompt
|
||||
session_id_pattern = r"<@!\d+>"
|
||||
session_id_result = re.search(session_id_pattern, message.content)
|
||||
if session_id_result:
|
||||
# 匹配出sessionid
|
||||
session_id = session_id_result.group(0)
|
||||
# 添加新条目进入缓存的prompt
|
||||
session_dict[session_id] = "Human: "+ qq_msg + "\nAI: "
|
||||
# 请求chatGPT获得结果
|
||||
chatgpt_res = await chatgpt.chat(session_dict[session_id])
|
||||
# 处理结果文本
|
||||
chatgpt_res = chatgpt_res.strip()
|
||||
session_dict[session_id] += chatgpt_res + "\n"
|
||||
print(f'{session_id} 目前prompt: {session_dict[session_id]}' )
|
||||
# 发送qq信息
|
||||
await message.reply(content=f"[ChatGPT]{chatgpt_res}")
|
||||
|
||||
def initBot(chatgpt_inst):
|
||||
global chatgpt
|
||||
|
||||
Reference in New Issue
Block a user