Skip to content

Commit bca9483

Browse files
committed
fix: short-term-mem test
1 parent dd46e44 commit bca9483

File tree

3 files changed

+10
-9
lines changed

3 files changed

+10
-9
lines changed

tests/test_short_term_memory.py

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
import asyncio
1616
import os
1717

18-
import veadk.memory.short_term_memory
1918
from veadk.memory.short_term_memory import ShortTermMemory
2019
from veadk.utils.misc import formatted_timestamp
2120

@@ -35,11 +34,11 @@ def test_short_term_memory():
3534
)
3635
assert session is not None
3736

38-
# database - local
39-
veadk.memory.short_term_memory.DEFAULT_LOCAL_DATABASE_PATH = (
40-
f"/tmp/tmp_for_test_{formatted_timestamp()}.db"
37+
# sqlite
38+
memory = ShortTermMemory(
39+
backend="sqlite",
40+
local_database_path=f"/tmp/tmp_for_test_{formatted_timestamp()}.db",
4141
)
42-
memory = ShortTermMemory(backend="database")
4342
asyncio.run(
4443
memory.session_service.create_session(
4544
app_name="app", user_id="user", session_id="session"
@@ -51,5 +50,5 @@ def test_short_term_memory():
5150
)
5251
)
5352
assert session is not None
54-
assert os.path.exists(veadk.memory.short_term_memory.DEFAULT_LOCAL_DATABASE_PATH)
55-
os.remove(veadk.memory.short_term_memory.DEFAULT_LOCAL_DATABASE_PATH)
53+
assert os.path.exists(memory.local_database_path)
54+
os.remove(memory.local_database_path)

veadk/memory/short_term_memory.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,9 @@ def wrapper(*args, **kwargs):
5050

5151

5252
class ShortTermMemory(BaseModel):
53-
backend: Literal["local", "mysql", "sqlite", "redis", "database"] = "local"
53+
backend: Literal["local", "mysql", "sqlite", "redis", "postgresql", "database"] = (
54+
"local"
55+
)
5456
"""Short term memory backend. `Local` for in-memory storage, `redis` for redis storage, `mysql` for mysql / PostgreSQL storage. `sqlite` for sqlite storage."""
5557

5658
backend_configs: dict = Field(default_factory=dict)

veadk/memory/short_term_memory_backends/postgresql_backend.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ class PostgreSqlSTMBackend(BaseShortTermMemoryBackend):
3232
postgresql_config: PostgreSqlConfig = Field(default_factory=PostgreSqlConfig)
3333

3434
def model_post_init(self, context: Any) -> None:
35-
self._db_url = f"postgresql://{self.postgresql_config.user}:{self.postgresql_config.password}@{self.postgresql_config.host}:{self.postgresql_config.port}/{self.postgresql_config.database}"
35+
self._db_url = f"postgresql+postgresql://{self.postgresql_config.user}:{self.postgresql_config.password}@{self.postgresql_config.host}:{self.postgresql_config.port}/{self.postgresql_config.database}"
3636

3737
@cached_property
3838
@override

0 commit comments

Comments
 (0)