From 78bf46d3bda842298dbbfce844819b2e5a2320ba Mon Sep 17 00:00:00 2001 From: nalbam Date: Tue, 20 Aug 2024 10:28:29 +0900 Subject: [PATCH] chore: Refactor conversation prompts and handling in handler.py --- handler.py | 15 ++++----------- 1 file changed, 4 insertions(+), 11 deletions(-) diff --git a/handler.py b/handler.py index 33feeae..f89a19a 100644 --- a/handler.py +++ b/handler.py @@ -194,14 +194,7 @@ def conversations_replies(channel, ts, client_msg_id): if message.get("bot_id", "") != "": role = "assistant" - contexts.append( - { - "role": role, - "content": message.get("text", ""), - } - ) - - # print("conversations_replies: messages size: {}".format(sys.getsizeof(messages))) + contexts.append("{}: {}".format(role, message.get("text", ""))) if sys.getsizeof(contexts) > MAX_LEN_BEDROCK: contexts.pop(0) # remove the oldest message @@ -332,8 +325,8 @@ def conversation(say: Say, thread_ts, query, channel, client_msg_id): "Use the following pieces of information to provide a concise answer to the question enclosed in tags." ) prompts.append("") - for reply in contexts: - prompts.append(reply["content"]) + for context in contexts: + prompts.append(context) prompts.append("") else: # Get the previous conversation contexts @@ -344,7 +337,7 @@ def conversation(say: Say, thread_ts, query, channel, client_msg_id): prompts.append("") for context in contexts: - prompts.append(context["content"]) + prompts.append(context) prompts.append("") # Add the question to the prompts