diff --git a/controller.py b/controller.py index 44291099..3da24fb5 100644 --- a/controller.py +++ b/controller.py @@ -3,8 +3,9 @@ from fastapi.responses import HTMLResponse from typing import List, Dict import asyncio -import time + from datetime import datetime +import pytz import logging from fastapi.templating import Jinja2Templates import traceback @@ -28,11 +29,13 @@ stream_logs = logging.StreamHandler() stream_logs.setLevel(logging.INFO) +france_tz = pytz.timezone("Europe/Paris") + @app.post("/outages/", status_code=201) async def create_outage(model_name: str, reason: str = None): outage = { - "detection_time": datetime.now().isoformat(), + "detection_time": datetime.now(tz=france_tz).isoformat(), "model_name": model_name, "reason": reason, } diff --git a/create_tables.sql b/create_tables.sql index b307ca7e..195e7cbd 100644 --- a/create_tables.sql +++ b/create_tables.sql @@ -1,6 +1,6 @@ CREATE TABLE logs ( - time TIMESTAMP NOT NULL, + time TIMESTAMPTZ NOT NULL, level VARCHAR(50) NOT NULL, message TEXT NOT NULL, query_params JSONB, @@ -11,7 +11,7 @@ CREATE TABLE CREATE TABLE votes ( - tstamp TIMESTAMP NOT NULL, + tstamp TIMESTAMPTZ NOT NULL, model_a_name VARCHAR(255) NOT NULL, model_b_name VARCHAR(255) NOT NULL, model_pair_name JSONB NOT NULL, @@ -37,7 +37,10 @@ CREATE TABLE CREATE TABLE profiles ( - tstamp TIMESTAMP NOT NULL, +-- ALTER COLUMN event_time +-- SET DATA TYPE TIMESTAMPTZ +-- USING tstamp AT TIME ZONE 'UTC'; + tstamp TIMESTAMPTZ NOT NULL, chatbot_use VARCHAR(255), gender VARCHAR(255), age VARCHAR(255), diff --git a/languia/block_conversation.py b/languia/block_conversation.py index 207d7812..73f9542b 100644 --- a/languia/block_conversation.py +++ b/languia/block_conversation.py @@ -2,14 +2,9 @@ The gradio utilities for chatting with a single model. """ -import datetime -import json -import os -import time import uuid import gradio as gr -import requests from fastchat.constants import ( WORKER_API_TIMEOUT, @@ -97,7 +92,7 @@ def bot_response( ): ip = get_ip(request) logger.info(f"bot_response. ip: {ip}") - start_tstamp = time.time() + # start_tstamp = time.time() temperature = float(temperature) top_p = float(top_p) max_new_tokens = int(max_new_tokens) diff --git a/languia/config.py b/languia/config.py index 557bb1ea..68d69d20 100644 --- a/languia/config.py +++ b/languia/config.py @@ -6,6 +6,11 @@ import datetime +import pytz + +# Get the timezone for France +france_tz = pytz.timezone("Europe/Paris") + env_debug = os.getenv("LANGUIA_DEBUG") if env_debug: @@ -16,7 +21,7 @@ else: debug = False -t = datetime.datetime.now() +t = datetime.datetime.now(france_tz) hostname = os.uname().nodename log_filename = f"logs-{hostname}-{t.year}-{t.month:02d}-{t.day:02d}.jsonl" import logging diff --git a/languia/utils.py b/languia/utils.py index 60400a8d..757acafd 100644 --- a/languia/utils.py +++ b/languia/utils.py @@ -18,6 +18,8 @@ import logging import datetime +import pytz +france_tz = pytz.timezone("Europe/Paris") import requests @@ -237,7 +239,7 @@ def save_profile( save poll data to file """ logger = logging.getLogger("languia") - t = datetime.datetime.now() + t = datetime.datetime.now(france_tz) profile_log_filename = f"profile-{t.year}-{t.month:02d}-{t.day:02d}-{t.hour:02d}-{t.minute:02d}-{request.session_hash}.json" profile_log_path = os.path.join(LOGDIR, profile_log_filename) @@ -405,7 +407,7 @@ def vote_last_response( form = (details["form"] - 1) * 25 if 1 <= details["form"] <= 5 else None style = (details["style"] - 1) * 25 if 1 <= details["style"] <= 5 else None - t = datetime.datetime.now() + t = datetime.datetime.now(france_tz) # TODO: Put opening_prompt in app_state? opening_prompt = str(get_opening_prompt(conversations[0])) diff --git a/requirements.txt b/requirements.txt index e5a57156..d9da412c 100644 --- a/requirements.txt +++ b/requirements.txt @@ -10,4 +10,5 @@ sentry_sdk google-auth python-slugify pandas -psycopg2-binary \ No newline at end of file +psycopg2-binary +pytz \ No newline at end of file