From f3d0405c76442710d4b8142d2a55d070d38fce04 Mon Sep 17 00:00:00 2001 From: nalbam Date: Mon, 19 Aug 2024 18:43:14 +0900 Subject: [PATCH] chore: Update conversation prompts and handling in handler.py --- handler.py | 30 +++++++++++++++++------------- 1 file changed, 17 insertions(+), 13 deletions(-) diff --git a/handler.py b/handler.py index 73b07ba..33feeae 100644 --- a/handler.py +++ b/handler.py @@ -212,7 +212,8 @@ def conversations_replies(channel, ts, client_msg_id): except Exception as e: print("conversations_replies: Error: {}".format(e)) - print("conversations_replies: {}".format(contexts)) + print("conversations_replies: getsizeof: {}".format(sys.getsizeof(contexts))) + # print("conversations_replies: {}".format(contexts)) return contexts @@ -321,17 +322,6 @@ def conversation(say: Say, thread_ts, query, channel, client_msg_id): prompts.append(SYSTEM_MESSAGE) try: - # Get the previous conversation contexts - if thread_ts != None: - chat_update(say, channel, thread_ts, latest_ts, MSG_PREVIOUS) - - contexts = conversations_replies(channel, thread_ts, client_msg_id) - - prompts.append("") - for reply in contexts: - prompts.append(reply["content"]) - prompts.append("") - # Get the knowledge base contexts if KNOWLEDGE_BASE_ID != "None": chat_update(say, channel, thread_ts, latest_ts, MSG_KNOWLEDGE) @@ -345,15 +335,29 @@ def conversation(say: Say, thread_ts, query, channel, client_msg_id): for reply in contexts: prompts.append(reply["content"]) prompts.append("") + else: + # Get the previous conversation contexts + if thread_ts != None: + chat_update(say, channel, thread_ts, latest_ts, MSG_PREVIOUS) + + contexts = conversations_replies(channel, thread_ts, client_msg_id) + + prompts.append("") + for context in contexts: + prompts.append(context["content"]) + prompts.append("") - # Generate the prompt + # Add the question to the prompts + prompts.append("") prompts.append("") prompts.append(query) prompts.append("") + prompts.append("") # prompts.append("The response should be specific and use statistics or numbers when possible.") prompts.append("Assistant:") + # Combine the prompts prompt = "\n".join(prompts) # print("conversation: prompt: {}".format(prompt))