Skip to content

Commit 956a395

Browse files
authored
fix: adk version update to 1.19 (#316)
1 parent d3bc73d commit 956a395

File tree

5 files changed

+25
-8
lines changed

5 files changed

+25
-8
lines changed

pyproject.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,9 @@ dependencies = [
3333
"llama-index-llms-openai-like>=0.5.1",
3434
"llama-index-vector-stores-opensearch>=0.6.1",
3535
"psycopg2-binary>=2.9.10", # For PostgreSQL database (short term memory)
36+
"asyncpg>=0.29.0", # For async PostgreSQL database (short term memory)
3637
"pymysql>=1.1.1", # For MySQL database (short term memory)
38+
"aiomysql>=0.3.2", # For async MySQL database (short term memory)
3739
"opensearch-py==2.8.0",
3840
"filetype>=1.2.0",
3941
]

veadk/memory/short_term_memory_backends/mysql_backend.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,12 @@
1515
from functools import cached_property
1616
from typing import Any
1717

18+
from google.adk import version as adk_version
1819
from google.adk.sessions import (
1920
BaseSessionService,
2021
DatabaseSessionService,
2122
)
23+
from packaging.version import parse as parse_version
2224
from pydantic import Field
2325
from typing_extensions import override
2426
from urllib.parse import quote_plus
@@ -36,7 +38,10 @@ class MysqlSTMBackend(BaseShortTermMemoryBackend):
3638
def model_post_init(self, context: Any) -> None:
3739
encoded_username = quote_plus(self.mysql_config.user)
3840
encoded_password = quote_plus(self.mysql_config.password)
39-
self._db_url = f"mysql+pymysql://{encoded_username}:{encoded_password}@{self.mysql_config.host}/{self.mysql_config.database}"
41+
if parse_version(adk_version.__version__) < parse_version("1.19.0"):
42+
self._db_url = f"mysql+pymysql://{encoded_username}:{encoded_password}@{self.mysql_config.host}/{self.mysql_config.database}"
43+
else:
44+
self._db_url = f"mysql+aiomysql://{encoded_username}:{encoded_password}@{self.mysql_config.host}/{self.mysql_config.database}"
4045

4146
@cached_property
4247
@override

veadk/memory/short_term_memory_backends/postgresql_backend.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,16 @@
1414

1515
from functools import cached_property
1616
from typing import Any
17-
from venv import logger
17+
from urllib.parse import quote_plus
1818

19+
from google.adk import version as adk_version
1920
from google.adk.sessions import (
2021
BaseSessionService,
2122
DatabaseSessionService,
2223
)
24+
from packaging.version import parse as parse_version
2325
from pydantic import Field
2426
from typing_extensions import override
25-
from urllib.parse import quote_plus
2627

2728
import veadk.config # noqa E401
2829
from veadk.configs.database_configs import PostgreSqlConfig
@@ -37,8 +38,10 @@ class PostgreSqlSTMBackend(BaseShortTermMemoryBackend):
3738
def model_post_init(self, context: Any) -> None:
3839
encoded_username = quote_plus(self.postgresql_config.user)
3940
encoded_password = quote_plus(self.postgresql_config.password)
40-
self._db_url = f"postgresql://{encoded_username}:{encoded_password}@{self.postgresql_config.host}:{self.postgresql_config.port}/{self.postgresql_config.database}"
41-
logger.debug(self._db_url)
41+
if parse_version(adk_version.__version__) < parse_version("1.19.0"):
42+
self._db_url = f"postgresql://{encoded_username}:{encoded_password}@{self.postgresql_config.host}:{self.postgresql_config.port}/{self.postgresql_config.database}"
43+
else:
44+
self._db_url = f"postgresql+asyncpg://{encoded_username}:{encoded_password}@{self.postgresql_config.host}:{self.postgresql_config.port}/{self.postgresql_config.database}"
4245

4346
@cached_property
4447
@override

veadk/memory/short_term_memory_backends/sqlite_backend.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,12 @@
1717
from functools import cached_property
1818
from typing import Any
1919

20+
from google.adk import version as adk_version
2021
from google.adk.sessions import (
2122
BaseSessionService,
2223
DatabaseSessionService,
2324
)
25+
from packaging.version import parse as parse_version
2426
from typing_extensions import override
2527

2628
from veadk.memory.short_term_memory_backends.base_backend import (
@@ -32,12 +34,17 @@ class SQLiteSTMBackend(BaseShortTermMemoryBackend):
3234
local_path: str
3335

3436
def model_post_init(self, context: Any) -> None:
37+
self.local_path = os.path.abspath(self.local_path)
3538
# if the DB file not exists, create it
3639
if not self._db_exists():
40+
os.makedirs(os.path.dirname(self.local_path), exist_ok=True)
3741
conn = sqlite3.connect(self.local_path)
3842
conn.close()
3943

40-
self._db_url = f"sqlite:///{self.local_path}"
44+
if parse_version(adk_version.__version__) < parse_version("1.19.0"):
45+
self._db_url = f"sqlite:///{self.local_path}"
46+
else:
47+
self._db_url = f"sqlite+aiosqlite:///{self.local_path}"
4148

4249
@cached_property
4350
@override

veadk/utils/patches.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,9 +82,9 @@ def patch_google_adk_telemetry() -> None:
8282

8383

8484
def patch_tracer() -> None:
85-
for mod_name, mod in sys.modules.items():
86-
from opentelemetry import trace
85+
from opentelemetry import trace
8786

87+
for mod_name, mod in tuple(sys.modules.items()):
8888
if mod_name.startswith("google.adk"):
8989
for var_name in dir(mod):
9090
var = getattr(mod, var_name, None)

0 commit comments

Comments
 (0)