Skip to content

Commit

Permalink
Refactor chat history structure in history.py and index.py
Browse files Browse the repository at this point in the history
  • Loading branch information
FloRul committed Mar 21, 2024
1 parent 7847dcf commit 01fc0d9
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 5 deletions.
24 changes: 22 additions & 2 deletions lambdas/inference/src/history.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,28 @@ def get(self, limit: int = 10):
json.loads(response["Payload"].read().decode("utf-8-sig"))["body"]
)
for x in body:
result.append({"role": "user", "content": x["HumanMessage"]})
result.append({"role": "assistant", "content": x["AssistantMessage"]})
result.append(
{
"role": "user",
"content": [
{
"type": "text",
"text": x["HumanMessage"],
},
],
}
)
result.append(
{
"role": "assistant",
"content": [
{
"type": "text",
"text": x["AssistantMessage"],
},
],
}
)
return result
except ClientError as e:
print("Error occurred: ", e.response["Error"]["Message"])
Expand Down
16 changes: 13 additions & 3 deletions lambdas/inference/src/index.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,9 +114,9 @@ def lambda_handler(event, context):
try:
source = event.get("queryStringParameters", {}).get("source", "message")
embedding_collection_name = event["queryStringParameters"]["collectionName"]

logger.info(str(event))

sessionId = str(uuid.uuid1())

if "sessionId" in event["queryStringParameters"]:
Expand All @@ -142,7 +142,17 @@ def lambda_handler(event, context):

logger.info("fetching chat history...")
chat_history = history.get(limit=5)
chat_history.append({"role": "user", "content": query})
chat_history.append(
{
"role": "user",
"content": [
{
"type": "text",
"text": query,
},
],
}
)

logger.info(f"Chat history: {chat_history}")

Expand Down

0 comments on commit 01fc0d9

Please sign in to comment.