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
@@ -18,7 +18,6 @@ from typing import Optional
|
||||
|
||||
from typing_extensions import override
|
||||
|
||||
from ..dependencies.vertexai import vertexai
|
||||
from .eval_case import Invocation
|
||||
from .eval_metrics import EvalMetric
|
||||
from .eval_metrics import Interval
|
||||
@@ -30,8 +29,6 @@ from .evaluator import Evaluator
|
||||
from .final_response_match_v1 import RougeEvaluator
|
||||
from .vertex_ai_eval_facade import _VertexAiEvalFacade
|
||||
|
||||
vertexai_types = vertexai.types
|
||||
|
||||
|
||||
class ResponseEvaluator(Evaluator):
|
||||
"""Evaluates Agent's responses.
|
||||
@@ -68,7 +65,9 @@ class ResponseEvaluator(Evaluator):
|
||||
metric_name = eval_metric.metric_name
|
||||
|
||||
if PrebuiltMetrics.RESPONSE_EVALUATION_SCORE.value == metric_name:
|
||||
self._metric_name = vertexai_types.PrebuiltMetric.COHERENCE
|
||||
from ..dependencies.vertexai import vertexai
|
||||
|
||||
self._metric_name = vertexai.types.PrebuiltMetric.COHERENCE
|
||||
elif PrebuiltMetrics.RESPONSE_MATCH_SCORE.value == metric_name:
|
||||
self._metric_name = metric_name
|
||||
else:
|
||||
|
||||
Reference in New Issue
Block a user