From 3d5102b854c3bb3efa292b3eb4cf4265fe733e00 Mon Sep 17 00:00:00 2001 From: cpacker Date: Thu, 21 Mar 2024 12:38:39 -0700 Subject: [PATCH 1/2] utc stragglers --- memgpt/models/pydantic_models.py | 8 ++++---- memgpt/server/rest_api/presets/index.py | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/memgpt/models/pydantic_models.py b/memgpt/models/pydantic_models.py index bb582b7cef..4b3956bca3 100644 --- a/memgpt/models/pydantic_models.py +++ b/memgpt/models/pydantic_models.py @@ -8,7 +8,7 @@ from sqlalchemy import JSON, Column, BINARY, TypeDecorator from memgpt.constants import DEFAULT_HUMAN, DEFAULT_MEMGPT_MODEL, DEFAULT_PERSONA, DEFAULT_PRESET, LLM_MAX_TOKENS, MAX_EMBEDDING_DIM -from memgpt.utils import get_human_text, get_persona_text, printd +from memgpt.utils import get_human_text, get_persona_text, printd, get_utc_time class LLMConfigModel(BaseModel): @@ -35,7 +35,7 @@ class PresetModel(BaseModel): id: uuid.UUID = Field(default_factory=uuid.uuid4, description="The unique identifier of the preset.") user_id: Optional[uuid.UUID] = Field(None, description="The unique identifier of the user who created the preset.") description: Optional[str] = Field(None, description="The description of the preset.") - created_at: datetime = Field(default_factory=datetime.now, description="The unix timestamp of when the preset was created.") + created_at: datetime = Field(default_factory=get_utc_time, description="The unix timestamp of when the preset was created.") system: str = Field(..., description="The system prompt of the preset.") persona: str = Field(default=get_persona_text(DEFAULT_PERSONA), description="The persona of the preset.") persona_name: Optional[str] = Field(None, description="The name of the persona of the preset.") @@ -60,7 +60,7 @@ class AgentStateModel(BaseModel): user_id: uuid.UUID = Field(..., description="The unique identifier of the user associated with the agent.") # timestamps - # created_at: datetime = Field(default_factory=datetime.now, description="The unix timestamp of when the agent was created.") + # created_at: datetime = Field(default_factory=get_utc_time, description="The unix timestamp of when the agent was created.") created_at: int = Field(..., description="The unix timestamp of when the agent was created.") # preset information @@ -100,7 +100,7 @@ class SourceModel(SQLModel, table=True): name: str = Field(..., description="The name of the source.") description: Optional[str] = Field(None, description="The description of the source.") user_id: uuid.UUID = Field(..., description="The unique identifier of the user associated with the source.") - created_at: datetime = Field(default_factory=datetime.now, description="The unix timestamp of when the source was created.") + created_at: datetime = Field(default_factory=get_utc_time, description="The unix timestamp of when the source was created.") id: uuid.UUID = Field(default_factory=uuid.uuid4, description="The unique identifier of the source.", primary_key=True) # embedding info # embedding_config: EmbeddingConfigModel = Field(..., description="The embedding configuration used by the source.") diff --git a/memgpt/server/rest_api/presets/index.py b/memgpt/server/rest_api/presets/index.py index b5c0055493..3a573003fb 100644 --- a/memgpt/server/rest_api/presets/index.py +++ b/memgpt/server/rest_api/presets/index.py @@ -35,7 +35,7 @@ class CreatePresetsRequest(BaseModel): id: Optional[Union[uuid.UUID, str]] = Field(default_factory=uuid.uuid4, description="The unique identifier of the preset.") # user_id: uuid.UUID = Field(..., description="The unique identifier of the user who created the preset.") description: Optional[str] = Field(None, description="The description of the preset.") - # created_at: datetime = Field(default_factory=datetime.now, description="The unix timestamp of when the preset was created.") + # created_at: datetime = Field(default_factory=get_utc_time, description="The unix timestamp of when the preset was created.") system: str = Field(..., description="The system prompt of the preset.") persona: str = Field(default=get_persona_text(DEFAULT_PERSONA), description="The persona of the preset.") human: str = Field(default=get_human_text(DEFAULT_HUMAN), description="The human of the preset.") From 6dd5658d7c2ed98d165553800f52519ca628c0c6 Mon Sep 17 00:00:00 2001 From: cpacker Date: Thu, 21 Mar 2024 12:46:48 -0700 Subject: [PATCH 2/2] remove direct import of UTC and instead use timezone.utc --- memgpt/functions/function_sets/base.py | 2 +- memgpt/utils.py | 4 ++-- tests/utils.py | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/memgpt/functions/function_sets/base.py b/memgpt/functions/function_sets/base.py index 72037b01c6..99e3ac426b 100644 --- a/memgpt/functions/function_sets/base.py +++ b/memgpt/functions/function_sets/base.py @@ -42,7 +42,7 @@ def pause_heartbeats(self: Agent, minutes: int) -> Optional[str]: minutes = min(MAX_PAUSE_HEARTBEATS, minutes) # Record the current time - self.pause_heartbeats_start = datetime.datetime.now(datetime.UTC) + self.pause_heartbeats_start = datetime.datetime.now(datetime.timezone.utc) # And record how long the pause should go for self.pause_heartbeats_minutes = int(minutes) diff --git a/memgpt/utils.py b/memgpt/utils.py index 2ca89e9d7e..d4c9aa00a4 100644 --- a/memgpt/utils.py +++ b/memgpt/utils.py @@ -1,4 +1,4 @@ -from datetime import datetime, UTC +from datetime import datetime, timezone import copy import re import json @@ -841,7 +841,7 @@ def get_local_time(timezone=None): def get_utc_time() -> datetime: """Get the current UTC time""" # return datetime.now(pytz.utc) - return datetime.now(UTC) + return datetime.now(timezone.utc) def format_datetime(dt): diff --git a/tests/utils.py b/tests/utils.py index 00088acd40..413f72b297 100644 --- a/tests/utils.py +++ b/tests/utils.py @@ -53,7 +53,7 @@ def wipe_memgpt_home(): """Wipes ~/.memgpt (moves to a backup), and initializes a new ~/.memgpt dir""" # Get the current timestamp in a readable format (e.g., YYYYMMDD_HHMMSS) - timestamp = datetime.datetime.now(datetime.UTC).strftime("%Y%m%d_%H%M%S") + timestamp = datetime.datetime.now(datetime.timezone.utc).strftime("%Y%m%d_%H%M%S") # Construct the new backup directory name with the timestamp backup_dir = f"~/.memgpt_test_backup_{timestamp}"