Skip to content

Commit

Permalink
Add logging statements for debugging and improve code readability
Browse files Browse the repository at this point in the history
  • Loading branch information
FloRul committed Mar 21, 2024
1 parent 04df6f6 commit 51585ae
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion lambdas/inference/src/index.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,27 +114,33 @@ 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"]:
sessionId = event["queryStringParameters"]["sessionId"]

logger.info(f"loading history for session {sessionId}")
history = History(session_id=sessionId)

query = event["queryStringParameters"]["query"]
docs = []

logger.info(f"intializing retrieval for query {query}")
# fetch documents
retrieval = Retrieval(
collection_name=embedding_collection_name,
relevance_treshold=ENV_VARS["relevance_treshold"],
)
docs = retrieval.fetch_documents(query=query, top_k=ENV_VARS["top_k"])

logger.info("preparing system prompt...")
# prepare the prompt
system_prompt = prepare_system_prompt(docs, source)

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

Expand Down

0 comments on commit 51585ae

Please sign in to comment.