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

fix: fix Application UI using UTC time #472

Merged
merged 5 commits into from
Nov 11, 2024
Merged
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
1 change: 1 addition & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ repos:
"types-requests",
"sqlmodel",
"types-Markdown",
types-tzlocal,
]
args: ["--check-untyped-defs", "--ignore-missing-imports"]
exclude: "^templates/"
Expand Down
17 changes: 10 additions & 7 deletions libs/ktem/ktem/db/base_models.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
import datetime
import uuid
from typing import Optional
from zoneinfo import ZoneInfo

from sqlalchemy import JSON, Column
from sqlmodel import Field, SQLModel
from theflow.settings import settings as flowsettings
from tzlocal import get_localzone


class BaseConversation(SQLModel):
Expand All @@ -26,9 +25,9 @@ class BaseConversation(SQLModel):
default_factory=lambda: uuid.uuid4().hex, primary_key=True, index=True
)
name: str = Field(
default_factory=lambda: datetime.datetime.now(
ZoneInfo(getattr(flowsettings, "TIME_ZONE", "UTC"))
).strftime("%Y-%m-%d %H:%M:%S")
default_factory=lambda: datetime.datetime.now(get_localzone()).strftime(
"%Y-%m-%d %H:%M:%S"
)
)
user: int = Field(default=0) # For now we only have one user

Expand All @@ -37,8 +36,12 @@ class BaseConversation(SQLModel):
# contains messages + current files + chat_suggestions
data_source: dict = Field(default={}, sa_column=Column(JSON))

date_created: datetime.datetime = Field(default_factory=datetime.datetime.utcnow)
date_updated: datetime.datetime = Field(default_factory=datetime.datetime.utcnow)
date_created: datetime.datetime = Field(
default_factory=lambda: datetime.datetime.now(get_localzone())
)
date_updated: datetime.datetime = Field(
default_factory=lambda: datetime.datetime.now(get_localzone())
)


class BaseUser(SQLModel):
Expand Down
9 changes: 5 additions & 4 deletions libs/ktem/ktem/index/file/index.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import uuid
from datetime import datetime
from typing import Any, Optional, Type

from ktem.components import filestorage_path, get_docstore, get_vectorstore
Expand All @@ -7,9 +8,9 @@
from sqlalchemy import JSON, Column, DateTime, Integer, String, UniqueConstraint
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy.ext.mutable import MutableDict
from sqlalchemy.sql import func
from theflow.settings import settings as flowsettings
from theflow.utils.modules import import_dotted_string
from tzlocal import get_localzone

from kotaemon.storages import BaseDocumentStore, BaseVectorStore

Expand Down Expand Up @@ -73,7 +74,7 @@ def _setup_resources(self):
"path": Column(String),
"size": Column(Integer, default=0),
"date_created": Column(
DateTime(timezone=True), server_default=func.now()
DateTime(timezone=True), default=datetime.now(get_localzone())
),
"user": Column(Integer, default=1),
"note": Column(
Expand All @@ -98,7 +99,7 @@ def _setup_resources(self):
"path": Column(String),
"size": Column(Integer, default=0),
"date_created": Column(
DateTime(timezone=True), server_default=func.now()
DateTime(timezone=True), default=datetime.now(get_localzone())
),
"user": Column(Integer, default=1),
"note": Column(
Expand Down Expand Up @@ -126,7 +127,7 @@ def _setup_resources(self):
"__tablename__": f"index__{self.id}__group",
"id": Column(Integer, primary_key=True, autoincrement=True),
"date_created": Column(
DateTime(timezone=True), server_default=func.now()
DateTime(timezone=True), default=datetime.now(get_localzone())
),
"name": Column(String, unique=True),
"user": Column(Integer, default=1),
Expand Down
1 change: 1 addition & 0 deletions libs/ktem/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ dependencies = [
"gradio>=4.31.0,<5",
"python-multipart==0.0.12", # required for gradio, pinning to avoid yanking issues with micropip (fixed in gradio >= 5.4.0)
"markdown>=3.6,<4",
"tzlocal>=5.0",
]
authors = [
{ name = "@trducng", email = "john@cinnamon.is" },
Expand Down
1 change: 1 addition & 0 deletions libs/ktem/requirements.txt
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
platformdirs
tzlocal
7 changes: 4 additions & 3 deletions scripts/migrate/migrate_chroma_db.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import uuid
from datetime import datetime

import chromadb
from ktem.index.models import Index
Expand All @@ -15,7 +16,7 @@
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy.ext.mutable import MutableDict
from sqlalchemy.orm import Session
from sqlalchemy.sql import func
from tzlocal import get_localzone


def _init_resource(private: bool = True, id: int = 1):
Expand All @@ -41,7 +42,7 @@ def _init_resource(private: bool = True, id: int = 1):
"path": Column(String),
"size": Column(Integer, default=0),
"date_created": Column(
DateTime(timezone=True), server_default=func.now()
DateTime(timezone=True), default=datetime.now(get_localzone())
),
"user": Column(Integer, default=1),
"note": Column(
Expand All @@ -66,7 +67,7 @@ def _init_resource(private: bool = True, id: int = 1):
"path": Column(String),
"size": Column(Integer, default=0),
"date_created": Column(
DateTime(timezone=True), server_default=func.now()
DateTime(timezone=True), default=datetime.now(get_localzone())
),
"user": Column(Integer, default=1),
"note": Column(
Expand Down
Loading