mirror of
https://github.com/encounter/adk-python.git
synced 2026-07-09 18:19:28 -07:00
chore: Lazy load Vertex AI dependencies in ADK modules
This is about 35% decrease. This change refactors several ADK modules to import `vertexai` and its submodules only when they are first used, rather than at the top of the file. This improves module load times by avoiding unnecessary imports of large dependencies. Imports are also placed within `if TYPE_CHECKING:` blocks where appropriate. Co-authored-by: Liang Wu <wuliang@google.com> PiperOrigin-RevId: 829017293
This commit is contained in:
committed by
Copybara-Service
parent
5f057498a2
commit
44d45fe9cd
@@ -20,16 +20,14 @@ import logging
|
||||
import re
|
||||
from typing import Any
|
||||
from typing import Optional
|
||||
from typing import TYPE_CHECKING
|
||||
from typing import Union
|
||||
|
||||
from google.genai import types
|
||||
from google.genai.errors import ClientError
|
||||
from tenacity import retry
|
||||
from tenacity import retry_if_result
|
||||
from tenacity import stop_after_attempt
|
||||
from tenacity import wait_exponential
|
||||
from typing_extensions import override
|
||||
import vertexai
|
||||
|
||||
if TYPE_CHECKING:
|
||||
import vertexai
|
||||
|
||||
from . import _session_util
|
||||
from ..events.event import Event
|
||||
@@ -326,6 +324,8 @@ class VertexAiSessionService(BaseSessionService):
|
||||
Returns:
|
||||
An API client for the given project and location or express mode api key.
|
||||
"""
|
||||
import vertexai
|
||||
|
||||
return vertexai.Client(
|
||||
project=self._project,
|
||||
location=self._location,
|
||||
|
||||
Reference in New Issue
Block a user