Skip to content

Commit

Permalink
fix: timestamps
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexisVLRT committed Jan 30, 2024
1 parent 03bb36e commit 832e10e
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 5 deletions.
4 changes: 2 additions & 2 deletions backend/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ async def get_current_user(token: str = Depends(oauth2_scheme)) -> User:
@app.post("/chat/new")
async def chat_new(current_user: User = Depends(get_current_user)) -> dict:
chat_id = str(uuid4())
timestamp = datetime.now().isoformat()
timestamp = datetime.utcnow().isoformat()
user_id = current_user.email
with Database() as connection:
connection.execute(
Expand Down Expand Up @@ -177,7 +177,7 @@ async def log_response_to_db(chat_id: str, full_response: str):
with Database() as connection:
connection.execute(
"INSERT INTO message (id, timestamp, chat_id, sender, content) VALUES (?, ?, ?, ?, ?)",
(response_id, datetime.now().isoformat(), chat_id, "assistant", full_response),
(response_id, datetime.utcnow().isoformat(), chat_id, "assistant", full_response),
)

async def memorize_response(rag_config: RagConfig, chat_id: str, question: str, answer: str):
Expand Down
3 changes: 1 addition & 2 deletions frontend/lib/chat.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@ class Message:

def __post_init__(self):
self.id = str(uuid4()) if self.id is None else self.id
self.timestamp = datetime.now().isoformat() if self.timestamp is None else self.timestamp

self.timestamp = datetime.utcnow().isoformat() if self.timestamp is None else self.timestamp

def chat():
prompt = st.chat_input("Say something")
Expand Down
2 changes: 1 addition & 1 deletion frontend/lib/sidebar.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def sidebar():
chats_by_time_ago = {}
for chat in chat_list:
chat_id, timestamp = chat["id"], chat["timestamp"]
time_ago = humanize.naturaltime(datetime.now() - datetime.fromisoformat(timestamp))
time_ago = humanize.naturaltime(datetime.utcnow() - datetime.fromisoformat(timestamp))
if time_ago not in chats_by_time_ago:
chats_by_time_ago[time_ago] = []
chats_by_time_ago[time_ago].append(chat)
Expand Down

0 comments on commit 832e10e

Please sign in to comment.