Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add timezone #16

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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,
}
Expand Down
9 changes: 6 additions & 3 deletions create_tables.sql
Original file line number Diff line number Diff line change
@@ -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,
Expand All @@ -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,
Expand All @@ -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),
Expand Down
7 changes: 1 addition & 6 deletions languia/block_conversation.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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)
Expand Down
7 changes: 6 additions & 1 deletion languia/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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
Expand Down
6 changes: 4 additions & 2 deletions languia/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
import logging

import datetime
import pytz
france_tz = pytz.timezone("Europe/Paris")

import requests

Expand Down Expand Up @@ -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)

Expand Down Expand Up @@ -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]))
Expand Down
3 changes: 2 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,5 @@ sentry_sdk
google-auth
python-slugify
pandas
psycopg2-binary
psycopg2-binary
pytz