chore: Defer import of live, Client and _transformers in google.genai

This is targeting the Client import mostly, but also prevents future latency increase if the other modules in genai adds more 3p dependencies. This change will make ADK only import `live`, `Client` and `_transformers` just-in-time, therefore cutting down cold start latency.

PiperOrigin-RevId: 831244349
This commit is contained in:
Google Team Member
2025-11-11 23:56:20 -08:00
committed by Copybara-Service
parent 37ee1869b5
commit b2c8ba5806
6 changed files with 12 additions and 26 deletions
+6 -6
View File
@@ -46,7 +46,7 @@ def llm_request():
@pytest.mark.asyncio
@mock.patch('google.genai.Client')
@mock.patch('google.adk.models.apigee_llm.Client')
async def test_generate_content_async_non_streaming(
mock_client_constructor, llm_request
):
@@ -96,7 +96,7 @@ async def test_generate_content_async_non_streaming(
@pytest.mark.asyncio
@mock.patch('google.genai.Client')
@mock.patch('google.adk.models.apigee_llm.Client')
async def test_generate_content_async_streaming(
mock_client_constructor, llm_request
):
@@ -167,7 +167,7 @@ async def test_generate_content_async_streaming(
@pytest.mark.asyncio
@mock.patch('google.genai.Client')
@mock.patch('google.adk.models.apigee_llm.Client')
async def test_generate_content_async_with_custom_headers(
mock_client_constructor, llm_request
):
@@ -207,7 +207,7 @@ async def test_generate_content_async_with_custom_headers(
@pytest.mark.asyncio
@mock.patch('google.genai.Client')
@mock.patch('google.adk.models.apigee_llm.Client')
async def test_vertex_model_path_parsing(mock_client_constructor):
"""Tests that Vertex AI model paths are parsed correctly."""
apigee_llm = ApigeeLlm(model=APIGEE_VERTEX_MODEL_ID, proxy_url=PROXY_URL)
@@ -249,7 +249,7 @@ async def test_vertex_model_path_parsing(mock_client_constructor):
@pytest.mark.asyncio
@mock.patch('google.genai.Client')
@mock.patch('google.adk.models.apigee_llm.Client')
async def test_proxy_url_from_env_variable(mock_client_constructor):
"""Tests that proxy_url is read from environment variable."""
with mock.patch.dict(
@@ -381,7 +381,7 @@ def test_vertex_model_missing_project_or_location_raises_error(
),
],
)
@mock.patch('google.genai.Client')
@mock.patch('google.adk.models.apigee_llm.Client')
async def test_model_string_parsing_and_client_initialization(
mock_client_constructor,
model_string,