Skip to content

Commit fa4e6ba

Browse files
authored
bug fixed for v3
1 parent 84f4d26 commit fa4e6ba

1 file changed

Lines changed: 15 additions & 9 deletions

File tree

talentBot.py

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -59,34 +59,38 @@ def process_synology_chat_message(event, refresh_keywords=None,
5959
message = event.get('text')
6060
username = event.get('username')
6161

62+
63+
6264
# Maintain conversation history
6365
if user_id not in conversation_history:
6466
conversation_history[user_id] = {"username": username,
6567
"messages": [{"role": "system", "content": chatbot_character}],
6668
"last_timestamp": int(time.time())}
67-
conversation_history[user_id]["messages"].append({"role": "user", "content": message})
68-
# Truncate conversation history if it exceeds the maximum length
69-
if len(conversation_history[user_id]["messages"]) > max_conversation_length:
70-
conversation_history[user_id]["messages"] = conversation_history[user_id]["messages"][
71-
-max_conversation_length:]
72-
7369

7470
# Check for refresh_prompt input to start a new conversation
7571
if refresh_keywords is None:
7672
refresh_keywords = ["new", "refresh", "00", "restart", "刷新", "新话题", "退下", "结束", "over"]
77-
if len(message) > 0 and message.strip().lower() in refresh_keywords:
73+
if message.strip().lower() in refresh_keywords:
7874
send_back_message(user_id, "好的,开启一下新话题。")
7975
conversation_history[user_id]["messages"] = conversation_history[user_id]["messages"][0:1]
8076
index = GPTSimpleVectorIndex([])
77+
conversation_history[user_id]["last_timestamp"] = int(time.time())
8178
return "----------------------------"
8279

8380
# Check if the conversation has been idle for 30 minutes (1800 seconds)
8481
if int(time.time()) - conversation_history[user_id]["last_timestamp"] >= max_time_gap * 60:
8582
conversation_history[user_id]["messages"] = conversation_history[user_id]["messages"][0:1]
8683
index = GPTSimpleVectorIndex([])
8784

88-
# update timestamp
89-
conversation_history[user_id]["last_timestamp"] = int(time.time())
85+
86+
# Truncate conversation history if it exceeds the maximum length
87+
if len(conversation_history[user_id]["messages"]) > max_conversation_length:
88+
conversation_history[user_id]["messages"] = conversation_history[user_id]["messages"][
89+
-max_conversation_length:]
90+
91+
92+
conversation_history[user_id]["messages"].append({"role": "user", "content": message})
93+
9094

9195
# check and execute python code
9296
code_results = separate_channel(message)
@@ -168,6 +172,8 @@ def process_synology_chat_message(event, refresh_keywords=None,
168172
else:
169173
send_back_message(user_id, response_text)
170174

175+
# update timestamp
176+
conversation_history[user_id]["last_timestamp"] = int(time.time())
171177
return "Message processed", 200
172178

173179

0 commit comments

Comments
 (0)