Skip to content

Commit

Permalink
fix: additions to utc patch (#1176) (#1177)
Browse files Browse the repository at this point in the history
  • Loading branch information
cpacker authored Mar 21, 2024
1 parent c9e48b3 commit 4dd1c26
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 9 deletions.
2 changes: 1 addition & 1 deletion memgpt/functions/function_sets/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
8 changes: 4 additions & 4 deletions memgpt/models/pydantic_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -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.")
Expand All @@ -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
Expand Down Expand Up @@ -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.")
Expand Down
2 changes: 1 addition & 1 deletion memgpt/server/rest_api/presets/index.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.")
Expand Down
4 changes: 2 additions & 2 deletions memgpt/utils.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from datetime import datetime, UTC
from datetime import datetime, timezone
import copy
import re
import json
Expand Down Expand Up @@ -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):
Expand Down
2 changes: 1 addition & 1 deletion tests/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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}"
Expand Down

0 comments on commit 4dd1c26

Please sign in to comment.