Skip to content

Commit

Permalink
add created_at and updated_at to the cosmos users collection
Browse files Browse the repository at this point in the history
This PR adds two new fields to the users collection the created_at field UTC time that gets created when a user starts a new coneversation, and the updated_at time UTC time for the last update that happened to the conversation
  • Loading branch information
john0isaac committed Sep 15, 2024
1 parent a944707 commit 1d0aecb
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions src/quartapp/config_base.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import json
import os
from abc import ABC, abstractmethod
from datetime import datetime, timezone
from urllib.parse import quote_plus

from langchain_core.documents import Document
Expand Down Expand Up @@ -63,7 +64,12 @@ async def add_to_cosmos(
raise IndexError
old_messages.append(new_message)
self.setup._database_setup._users_collection.insert_one(
{"_id": new_session_state, "messages": old_messages}
{
"_id": new_session_state,
"messages": old_messages,
"created_at": datetime.now(timezone.utc), # noqa: UP017
"updated_at": datetime.now(timezone.utc), # noqa: UP017
}
)
return True
except (AttributeError, ConfigurationError, InvalidName, InvalidOperation, OperationFailure, IndexError):
Expand All @@ -73,10 +79,12 @@ async def add_to_cosmos(
if len(old_messages) == 0 or len(new_message) == 0 or len(new_session_state) == 0:
raise IndexError
self.setup._database_setup._users_collection.update_one(
{"_id": new_session_state}, {"$push": {"messages": old_messages[-1]}}
{"_id": new_session_state},
{"$push": {"messages": {"$each": [old_messages[-1], new_message]}}}, # noqa: UP017
)
self.setup._database_setup._users_collection.update_one(
{"_id": new_session_state}, {"$push": {"messages": new_message}}
{"_id": new_session_state},
{"$set": {"updated_at": datetime.now(timezone.utc)}}, # noqa: UP017
)
return True
except (AttributeError, ConfigurationError, InvalidName, InvalidOperation, OperationFailure, IndexError):
Expand Down

0 comments on commit 1d0aecb

Please sign in to comment.