Skip to content

Commit

Permalink
Fix for UTC warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
simonw committed Dec 12, 2024
1 parent b8e8052 commit 8378da6
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 9 deletions.
4 changes: 2 additions & 2 deletions llm/default_plugins/openai_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -182,8 +182,8 @@ def models(json_, key):
to_print = []
for model in models:
# Print id, owned_by, root, created as ISO 8601
created_str = datetime.datetime.utcfromtimestamp(
model["created"]
created_str = datetime.datetime.fromtimestamp(
model["created"], datetime.timezone.utc
).isoformat()
to_print.append(
{
Expand Down
5 changes: 4 additions & 1 deletion llm/migrations.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,10 @@ def migrate(db):
if name not in already_applied:
fn(db)
db["_llm_migrations"].insert(
{"name": name, "applied_at": str(datetime.datetime.utcnow())}
{
"name": name,
"applied_at": str(datetime.datetime.now(datetime.timezone.utc)),
}
)
already_applied.add(name)

Expand Down
4 changes: 2 additions & 2 deletions llm/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -385,7 +385,7 @@ def usage(self) -> Usage:

def __iter__(self) -> Iterator[str]:
self._start = time.monotonic()
self._start_utcnow = datetime.datetime.utcnow()
self._start_utcnow = datetime.datetime.now(datetime.timezone.utc)
if self._done:
yield from self._chunks
return
Expand Down Expand Up @@ -434,7 +434,7 @@ async def _on_done(self):

def __aiter__(self):
self._start = time.monotonic()
self._start_utcnow = datetime.datetime.utcnow()
self._start_utcnow = datetime.datetime.now(datetime.timezone.utc)
return self

async def __anext__(self) -> str:
Expand Down
6 changes: 3 additions & 3 deletions tests/test_cli_openai_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,9 @@ def test_openai_models(mocked_models):
result = runner.invoke(cli, ["openai", "models", "--key", "x"])
assert result.exit_code == 0
assert result.output == (
"id owned_by created \n"
"ada:2020-05-03 openai 2020-05-03T20:26:40\n"
"babbage:2020-05-03 openai 2020-05-03T20:26:40\n"
"id owned_by created \n"
"ada:2020-05-03 openai 2020-05-03T20:26:40+00:00\n"
"babbage:2020-05-03 openai 2020-05-03T20:26:40+00:00\n"
)


Expand Down
2 changes: 1 addition & 1 deletion tests/test_llm.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def log_path(user_path):
log_path = str(user_path / "logs.db")
db = sqlite_utils.Database(log_path)
migrate(db)
start = datetime.datetime.utcnow()
start = datetime.datetime.now(datetime.timezone.utc)
db["responses"].insert_all(
{
"id": str(ULID()).lower(),
Expand Down

0 comments on commit 8378da6

Please sign in to comment.