Fix for UTC warnings

Closes #672
This commit is contained in:
Simon Willison 2024-12-12 14:57:23 -08:00 committed by GitHub
parent b8e8052229
commit 571f4b2a4d
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 12 additions and 9 deletions

View file

@ -182,8 +182,8 @@ def register_commands(cli):
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(
{

View file

@ -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)

View file

@ -385,7 +385,7 @@ class Response(_BaseResponse):
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
@ -434,7 +434,7 @@ class AsyncResponse(_BaseResponse):
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:

View file

@ -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"
)

View file

@ -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(),