Skip to content

Commit

Permalink
Merge pull request #16 from nalbam/main
Browse files Browse the repository at this point in the history
chore: Refactor conversation prompts and handling in handler.py
  • Loading branch information
nalbam authored Aug 20, 2024
2 parents cd2fc8e + 78bf46d commit 9517f7e
Showing 1 changed file with 4 additions and 11 deletions.
15 changes: 4 additions & 11 deletions handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 <question> tags."
)
prompts.append("<context>")
for reply in contexts:
prompts.append(reply["content"])
for context in contexts:
prompts.append(context)
prompts.append("</context>")
else:
# Get the previous conversation contexts
Expand All @@ -344,7 +337,7 @@ def conversation(say: Say, thread_ts, query, channel, client_msg_id):

prompts.append("<context>")
for context in contexts:
prompts.append(context["content"])
prompts.append(context)
prompts.append("</context>")

# Add the question to the prompts
Expand Down

0 comments on commit 9517f7e

Please sign in to comment.