Skip to content

The fastest, litest AI Gateway. Rust core with Python SDK. Call 100+ LLM APIs in OpenAI (or native) format with cost tracking, guardrails, load balancing, and logging [Bedrock, Azure, OpenAI, Anthropic, OpenAI, VertexAI, vLLM, Nvidia NIM]

[Feat] Add gemini-cli support - call VertexAI models through LiteLLM Native gemini routes (#12053)

Ishaan Jaff14d05fe42276
diff --git a/litellm/__init__.py b/litellm/__init__.py
index 2921c0600d9..c2064d5d57b 100644
--- a/litellm/__init__.py
+++ b/litellm/__init__.py
@@ -1151,7 +1151,6 @@ from .fine_tuning.main import *
from .files.main import *
from .scheduler import *
from .cost_calculator import response_cost_calculator, cost_per_token
-
### ADAPTERS ###
from .types.adapter import AdapterItem
import litellm.anthropic_interface as anthropic
diff --git a/litellm/google_genai/main.py b/litellm/google_genai/main.py
index 6c27ecdadf1..171569bbcbc 100644
--- a/litellm/google_genai/main.py
+++ b/litellm/google_genai/main.py
@@ -321,7 +321,7 @@ async def agenerate_content_stream(
# LiteLLM specific params,
custom_llm_provider: Optional[str] = None,
**kwargs
-) -> AsyncIterator[Any]:
+) -> Any:
"""
Async: Generate content using Google GenAI with streaming response
"""
@@ -346,7 +346,8 @@ async def agenerate_content_stream(
)
# Call the handler with async enabled and streaming
- async_generator = await base_llm_http_handler.generate_content_handler(
+ # Return the coroutine directly for the router to handle
+ return await base_llm_http_handler.generate_content_handler(
model=setup_result.model,
contents=contents,
generate_content_provider_config=setup_result.generate_content_provider_config,
@@ -362,10 +363,6 @@ async def agenerate_content_stream(
stream=True,
litellm_metadata=kwargs.get("litellm_metadata", {}),
)
-
- # Iterate over the async generator
- async for chunk in async_generator:
- yield chunk
except Exception as e:
raise litellm.exception_type(
diff --git a/litellm/google_genai/streaming_iterator.py b/litellm/google_genai/streaming_iterator.py
index 9e88e9d772e..a38d3c18361 100644
--- a/litellm/google_genai/streaming_iterator.py
+++ b/litellm/google_genai/streaming_iterator.py
@@ -55,7 +55,7 @@ class GoogleGenAIGenerateContentStreamingIterator(BaseGoogleGenAIGenerateContent
self.litellm_metadata = litellm_metadata
self.custom_llm_provider = custom_llm_provider
# Store the iterator once to avoid multiple stream consumption
- self.stream_iterator = response.iter_lines()
+ self.stream_iterator = response.iter_bytes()
def __iter__(self):
return self
@@ -103,7 +103,7 @@ class AsyncGoogleGenAIGenerateContentStreamingIterator(BaseGoogleGenAIGenerateCo
self.litellm_metadata = litellm_metadata
self.custom_llm_provider = custom_llm_provider
# Store the async iterator once to avoid multiple stream consumption
- self.stream_iterator = response.aiter_lines()
+ self.stream_iterator = response.aiter_bytes()
def __aiter__(self):
return self
diff --git a/litellm/llms/gemini/google_genai/transformation.py b/litellm/llms/gemini/google_genai/transformation.py
index 5751d28265f..1fe2f4e6548 100644
--- a/litellm/llms/gemini/google_genai/transformation.py
+++ b/litellm/llms/gemini/google_genai/transformation.py
@@ -30,7 +30,7 @@ class GoogleGenAIConfig(BaseGoogleGenAIGenerateContentConfig, VertexLLM):
Configuration for calling Google models in their native format.
"""
@property
- def custom_llm_provider(self) -> Literal["gemini"]:
+ def custom_llm_provider(self) -> Literal["gemini", "vertex_ai"]:
return "gemini"
def __init__(self):
diff --git a/litellm/llms/vertex_ai/google_genai/transformation.py b/litellm/llms/vertex_ai/google_genai/transformation.py
new file mode 100644
index 00000000000..02825026e1b
--- /dev/null
+++ b/litellm/llms/vertex_ai/google_genai/transformation.py
@@ -0,0 +1,16 @@
+"""
+Transformation for Calling Google models in their native format.
+"""
+from typing import Literal
+
+from litellm.llms.gemini.google_genai.transformation import GoogleGenAIConfig
+
+
+class VertexAIGoogleGenAIConfig(GoogleGenAIConfig):
+ """
+ Configuration for calling Google models in their native format.
+ """
+ @property
+ def custom_llm_provider(self) -> Literal["gemini", "vertex_ai"]:
+ return "vertex_ai"
+
\ No newline at end of file
diff --git a/litellm/proxy/_types.py b/litellm/proxy/_types.py
index 111ef89f7df..63937297aa9 100644
--- a/litellm/proxy/_types.py
+++ b/litellm/proxy/_types.py
@@ -347,6 +347,17 @@ class LiteLLMRoutes(enum.Enum):
"/mcp/tools/call",
]
+ google_routes = [
+ "/v1beta/models/{model_name}:countTokens",
+ "/v1beta/models/{model_name}:generateContent",
+ "/v1beta/models/{model_name}:streamGenerateContent",
+
+ "/models/{model_name}:countTokens",
+ "/models/{model_name}:generateContent",
+ "/models/{model_name}:streamGenerateContent",
+ ]
+
+
apply_guardrail_routes = [
"/guardrails/apply_guardrail",
]
diff --git a/litellm/proxy/anthropic_endpoints/endpoints.py b/litellm/proxy/anthropic_endpoints/endpoints.py
index 024a56fc5b6..be8ce40566b 100644
--- a/litellm/proxy/anthropic_endpoints/endpoints.py
+++ b/litellm/proxy/anthropic_endpoints/endpoints.py
@@ -25,76 +25,6 @@ from litellm.proxy.utils import ProxyLogging
router = APIRouter()
-
-def return_anthropic_chunk(chunk: Any) -> str:
- """
- Helper function to format streaming chunks for Anthropic API format
-
- Args:
- chunk: A string or dictionary to be returned in SSE format
-
- Returns:
- str: A properly formatted SSE chunk string
- """
- if isinstance(chunk, dict):
- # Use safe_dumps for proper JSON serialization with circular reference detection
- chunk_str = safe_dumps(chunk)
- return f"{STREAM_SSE_DATA_PREFIX}{chunk_str}\n\n"
- else:
- return chunk
-
-
-async def async_data_generator_anthropic(
- response,
- user_api_key_dict: UserAPIKeyAuth,
- request_data: dict,
- proxy_logging_obj: ProxyLogging,
-):
- verbose_proxy_logger.debug("inside generator")
- try:
- time.time()
- async for chunk in response:
- verbose_proxy_logger.debug(
- "async_data_generator: received streaming chunk - {}".format(chunk)
- )
- ### CALL HOOKS ### - modify outgoing data
- chunk = await proxy_logging_obj.async_post_call_streaming_hook(
- user_api_key_dict=user_api_key_dict, response=chunk
- )
-
- # Format chunk using helper function
- yield return_anthropic_chunk(chunk)
- except Exception as e:
- verbose_proxy_logger.exception(
- "litellm.proxy.proxy_server.async_data_generator(): Exception occured - {}".format(
- str(e)
- )
- )
- await proxy_logging_obj.post_call_failure_hook(
- user_api_key_dict=user_api_key_dict,
- original_exception=e,
- request_data=request_data,
- )
- verbose_proxy_logger.debug(
- f"\033[1;31mAn error occurred: {e}\n\n Debug this by setting `--debug`, e.g. `litellm --model gpt-3.5-turbo --debug`"
- )
-
- if isinstance(e, HTTPException):
- raise e
- else:
- error_traceback = traceback.format_exc()
- error_msg = f"{str(e)}\n\n{error_traceback}"
-
- proxy_exception = ProxyException(
- message=getattr(e, "message", error_msg),
- type=getattr(e, "type", "None"),
- param=getattr(e, "param", "None"),
- code=getattr(e, "status_code", 500),
- )
- error_returned = json.dumps({"error": proxy_exception.to_dict()})
- yield f"{STREAM_SSE_DATA_PREFIX}{error_returned}\n\n"
-
-
@router.post(
"/v1/messages",
tags=["[beta] Anthropic `/v1/messages`"],
@@ -243,7 +173,7 @@ async def anthropic_response( # noqa: PLR0915
if (
"stream" in data and data["stream"] is True
): # use generate_responses to stream responses
- selected_data_generator = async_data_generator_anthropic(
+ selected_data_generator = ProxyBaseLLMRequestProcessing.async_sse_data_generator(
response=response,
user_api_key_dict=user_api_key_dict,
request_data=data,
diff --git a/litellm/proxy/common_request_processing.py b/litellm/proxy/common_request_processing.py
index 829a495e9db..afe596b03d5 100644
--- a/litellm/proxy/common_request_processing.py
+++ b/litellm/proxy/common_request_processing.py
@@ -1,5 +1,6 @@
import asyncio
import json
+import traceback
import uuid
from datetime import datetime
from typing import (
@@ -20,9 +21,13 @@ from fastapi.responses import Response, StreamingResponse
import litellm
from litellm._logging import verbose_proxy_logger
-from litellm.constants import DD_TRACER_STREAMING_CHUNK_YIELD_RESOURCE
+from litellm.constants import (
+ DD_TRACER_STREAMING_CHUNK_YIELD_RESOURCE,
+ STREAM_SSE_DATA_PREFIX,
+)
from litellm.litellm_core_utils.dd_tracing import tracer
from litellm.litellm_core_utils.litellm_logging import Logging as LiteLLMLoggingObj
+from litellm.litellm_core_utils.safe_json_dumps import safe_dumps
from litellm.proxy._types import ProxyException, UserAPIKeyAuth
from litellm.proxy.auth.auth_utils import check_response_size_is_safe
from litellm.proxy.common_utils.callback_utils import (
@@ -252,6 +257,8 @@ class ProxyBaseLLMRequestProcessing:
"aretrieve_fine_tuning_job",
"alist_input_items",
"aimage_edit",
+ "agenerate_content",
+ "agenerate_content_stream",
],
version: Optional[str] = None,
user_model: Optional[str] = None,
@@ -331,6 +338,8 @@ class ProxyBaseLLMRequestProcessing:
"atext_completion",
"aimage_edit",
"alist_input_items",
+ "agenerate_content",
+ "agenerate_content_stream",
],
proxy_logging_obj: ProxyLogging,
general_settings: dict,
@@ -344,6 +353,7 @@ class ProxyBaseLLMRequestProcessing:
user_max_tokens: Optional[int] = None,
user_api_base: Optional[str] = None,
version: Optional[str] = None,
+ is_streaming_request: Optional[bool] = False,
) -> Any:
"""
Common request processing logic for both chat completions and responses API endpoints
@@ -418,9 +428,7 @@ class ProxyBaseLLMRequestProcessing:
litellm_call_id=self.data.get("litellm_call_id", ""), status="success"
)
)
- if (
- "stream" in self.data and self.data["stream"] is True
- ): # use generate_responses to stream responses
+ if self._is_streaming_request(data=self.data, is_streaming_request=is_streaming_request): # use generate_responses to stream responses
custom_headers = ProxyBaseLLMRequestProcessing.get_custom_headers(
user_api_key_dict=user_api_key_dict,
call_id=logging_obj.litellm_call_id,
@@ -476,6 +484,22 @@ class ProxyBaseLLMRequestProcessing:
return response
+ def _is_streaming_request(
+ self, data: dict, is_streaming_request: Optional[bool] = False
+ ) -> bool:
+ """
+ Check if the request is a streaming request.
+
+ 1. is_streaming_request is a dynamic param passed in
+ 2. if "stream" in data and data["stream"] is True
+ """
+ if is_streaming_request is True:
+ return True
+ if "stream" in data and data["stream"] is True:
+ return True
+ return False
+
+
async def _handle_llm_api_exception(
self,
e: Exception,
@@ -545,3 +569,80 @@ class ProxyBaseLLMRequestProcessing:
return "completion"
elif route_type == "aresponses":
return "responses"
+
+ #########################################################
+ # Proxy Level Streaming Data Generator
+ #########################################################
+
+ @staticmethod
+ def return_sse_chunk(chunk: Any) -> str:
+ """
+ Helper function to format streaming chunks for Anthropic API format
+
+ Args:
+ chunk: A string or dictionary to be returned in SSE format
+
+ Returns:
+ str: A properly formatted SSE chunk string
+ """
+ if isinstance(chunk, dict):
+ # Use safe_dumps for proper JSON serialization with circular reference detection
+ chunk_str = safe_dumps(chunk)
+ return f"{STREAM_SSE_DATA_PREFIX}{chunk_str}\n\n"
+ else:
+ return chunk
+
+ @staticmethod
+ async def async_sse_data_generator(
+ response,
+ user_api_key_dict: UserAPIKeyAuth,
+ request_data: dict,
+ proxy_logging_obj: ProxyLogging,
+ ):
+ """
+ Anthropic /messages and Google /generateContent streaming data generator require SSE events
+ """
+ verbose_proxy_logger.debug("inside generator")
+ try:
+ async for chunk in response:
+ verbose_proxy_logger.debug(
+ "async_data_generator: received streaming chunk - {}".format(chunk)
+ )
+ ### CALL HOOKS ### - modify outgoing data
+ chunk = await proxy_logging_obj.async_post_call_streaming_hook(
+ user_api_key_dict=user_api_key_dict, response=chunk
+ )
+
+ # Format chunk using helper function
+ yield ProxyBaseLLMRequestProcessing.return_sse_chunk(chunk)
+ except Exception as e:
+ verbose_proxy_logger.exception(
+ "litellm.proxy.proxy_server.async_data_generator(): Exception occured - {}".format(
+ str(e)
+ )
+ )
+ await proxy_logging_obj.post_call_failure_hook(
+ user_api_key_dict=user_api_key_dict,
+ original_exception=e,
+ request_data=request_data,
+ )
+ verbose_proxy_logger.debug(
+ f"\033[1;31mAn error occurred: {e}\n\n Debug this by setting `--debug`, e.g. `litellm --model gpt-3.5-turbo --debug`"
+ )
+
+ if isinstance(e, HTTPException):
+ raise e
+ else:
+ error_traceback = traceback.format_exc()
+ error_msg = f"{str(e)}\n\n{error_traceback}"
+
+ proxy_exception = ProxyException(
+ message=getattr(e, "message", error_msg),
+ type=getattr(e, "type", "None"),
+ param=getattr(e, "param", "None"),
+ code=getattr(e, "status_code", 500),
+ )
+ error_returned = json.dumps({"error": proxy_exception.to_dict()})
+ yield f"{STREAM_SSE_DATA_PREFIX}{error_returned}\n\n"
+
+
diff --git a/litellm/proxy/google_endpoints/endpoints.py b/litellm/proxy/google_endpoints/endpoints.py
index 81e71b7b3ef..226fcf05aac 100644
--- a/litellm/proxy/google_endpoints/endpoints.py
+++ b/litellm/proxy/google_endpoints/endpoints.py
@@ -1,32 +1,154 @@
-from fastapi import APIRouter, Depends, Request
+from fastapi import APIRouter, Depends, Request, Response
-from litellm.proxy.auth.user_api_key_auth import user_api_key_auth
+from litellm.proxy._types import *
+from litellm.proxy.auth.user_api_key_auth import UserAPIKeyAuth, user_api_key_auth
+from litellm.proxy.common_request_processing import ProxyBaseLLMRequestProcessing
router = APIRouter(
tags=["google genai endpoints"],
)
[email protected]("/v1beta/models/{model_name}:countTokens", dependencies=[Depends(user_api_key_auth)])
-async def google_count_tokens(request: Request, model_name: str):
[email protected]("/v1beta/models/{model_name}:generateContent", dependencies=[Depends(user_api_key_auth)])
[email protected]("/models/{model_name}:generateContent", dependencies=[Depends(user_api_key_auth)])
+async def google_generate_content(
+ request: Request,
+ model_name: str,
+ fastapi_response: Response,
+ user_api_key_dict: UserAPIKeyAuth = Depends(user_api_key_auth),
+):
"""
- Not Implemented, this is a placeholder for the google genai countTokens endpoint.
+ Not Implemented, this is a placeholder for the google genai generateContent endpoint.
"""
- return {}
+ from litellm.proxy.proxy_server import (
+ _read_request_body,
+ general_settings,
+ llm_router,
+ proxy_config,
+ proxy_logging_obj,
+ select_data_generator,
+ user_api_base,
+ user_max_tokens,
+ user_model,
+ user_request_timeout,
+ user_temperature,
+ version,
+ )
+ data = await _read_request_body(request=request)
+ if "model" not in data:
+ data["model"] = model_name
+ processor = ProxyBaseLLMRequestProcessing(data=data)
+ try:
+ return await processor.base_process_llm_request(
+ request=request,
+ fastapi_response=fastapi_response,
+ user_api_key_dict=user_api_key_dict,
+ route_type="agenerate_content",
+ proxy_logging_obj=proxy_logging_obj,
+ llm_router=llm_router,
+ general_settings=general_settings,
+ proxy_config=proxy_config,
+ select_data_generator=select_data_generator,
+ model=None,
+ user_model=user_model,
+ user_temperature=user_temperature,
+ user_request_timeout=user_request_timeout,
+ user_max_tokens=user_max_tokens,
+ user_api_base=user_api_base,
+ version=version,
+ )
+ except Exception as e:
+ raise await processor._handle_llm_api_exception(
+ e=e,
+ user_api_key_dict=user_api_key_dict,
+ proxy_logging_obj=proxy_logging_obj,
+ version=version,
+ )
[email protected]("/v1beta/models/{model_name}:generateContent", dependencies=[Depends(user_api_key_auth)])
-async def google_generate_content(request: Request, model_name: str):
- """
- Not Implemented, this is a placeholder for the google genai generateContent endpoint.
+
+class GoogleAIStudioDataGenerator:
"""
- return {}
+ Ensures SSE data generator is used for Google AI Studio streaming responses
+ Thin wrapper around ProxyBaseLLMRequestProcessing.async_sse_data_generator
+ """
+ @staticmethod
+ def _select_data_generator(response, user_api_key_dict, request_data):
+ from litellm.proxy.proxy_server import proxy_logging_obj
+ return ProxyBaseLLMRequestProcessing.async_sse_data_generator(
+ response=response,
+ user_api_key_dict=user_api_key_dict,
+ request_data=request_data,
+ proxy_logging_obj=proxy_logging_obj,
+ )
@router.post("/v1beta/models/{model_name}:streamGenerateContent", dependencies=[Depends(user_api_key_auth)])
-async def google_stream_generate_content(request: Request, model_name: str):
[email protected]("/models/{model_name}:streamGenerateContent", dependencies=[Depends(user_api_key_auth)])
+async def google_stream_generate_content(
+ request: Request,
+ model_name: str,
+ fastapi_response: Response,
+ user_api_key_dict: UserAPIKeyAuth = Depends(user_api_key_auth),
+):
"""
Not Implemented, this is a placeholder for the google genai streamGenerateContent endpoint.
"""
- return {}
+ from litellm.proxy.proxy_server import (
+ _read_request_body,
+ general_settings,
+ llm_router,
+ proxy_config,
+ proxy_logging_obj,
+ user_api_base,
+ user_max_tokens,
+ user_model,
+ user_request_timeout,
+ user_temperature,
+ version,
+ )
+ data = await _read_request_body(request=request)
+ if "model" not in data:
+ data["model"] = model_name
+
+
+ processor = ProxyBaseLLMRequestProcessing(data=data)
+ try:
+ return await processor.base_process_llm_request(
+ request=request,
+ fastapi_response=fastapi_response,
+ user_api_key_dict=user_api_key_dict,
+ route_type="agenerate_content_stream",
+ proxy_logging_obj=proxy_logging_obj,
+ llm_router=llm_router,
+ general_settings=general_settings,
+ proxy_config=proxy_config,
+ select_data_generator=GoogleAIStudioDataGenerator._select_data_generator,
+ model=None,
+ user_model=user_model,
+ user_temperature=user_temperature,
+ user_request_timeout=user_request_timeout,
+ user_max_tokens=user_max_tokens,
+ user_api_base=user_api_base,
+ version=version,
+ is_streaming_request=True,
+ )
+ except Exception as e:
+ raise await processor._handle_llm_api_exception(
+ e=e,
+ user_api_key_dict=user_api_key_dict,
+ proxy_logging_obj=proxy_logging_obj,
+ version=version,
+ )
+
+
+
+
[email protected]("/v1beta/models/{model_name}:countTokens", dependencies=[Depends(user_api_key_auth)])
[email protected]("/models/{model_name}:countTokens", dependencies=[Depends(user_api_key_auth)])
+async def google_count_tokens(request: Request, model_name: str):
+ """
+ Not Implemented, this is a placeholder for the google genai countTokens endpoint.
+ """
+ return {}
diff --git a/litellm/proxy/proxy_config.yaml b/litellm/proxy/proxy_config.yaml
index 4550c1760a8..51b147d6fa3 100644
--- a/litellm/proxy/proxy_config.yaml
+++ b/litellm/proxy/proxy_config.yaml
@@ -1,8 +1,7 @@
model_list:
- - model_name: gemini/*
+ - model_name: vertex_ai/*
litellm_params:
- model: gemini/*
- api_key: os.environ/GEMINI_API_KEY
+ model: vertex_ai/*
- model_name: "anthropic/*"
litellm_params:
model: "anthropic/*"
diff --git a/litellm/proxy/route_llm_request.py b/litellm/proxy/route_llm_request.py
index ce623aa7f0c..e920210a75e 100644
--- a/litellm/proxy/route_llm_request.py
+++ b/litellm/proxy/route_llm_request.py
@@ -73,6 +73,8 @@ async def route_request(
"alist_input_items",
"_arealtime", # private function for realtime API
"aimage_edit",
+ "agenerate_content",
+ "agenerate_content_stream",
],
):
"""
diff --git a/litellm/router.py b/litellm/router.py
index acb3fb6f6ea..2d9796b62fa 100644
--- a/litellm/router.py
+++ b/litellm/router.py
@@ -781,6 +781,28 @@ class Router:
litellm.allm_passthrough_route, call_type="allm_passthrough_route"
)
+ #########################################################
+ # Gemini Native routes
+ #########################################################
+ from litellm.google_genai import (
+ agenerate_content,
+ agenerate_content_stream,
+ generate_content,
+ generate_content_stream,
+ )
+ self.agenerate_content = self.factory_function(
+ agenerate_content, call_type="agenerate_content"
+ )
+ self.generate_content = self.factory_function(
+ generate_content, call_type="generate_content"
+ )
+ self.agenerate_content_stream = self.factory_function(
+ agenerate_content_stream, call_type="agenerate_content_stream"
+ )
+ self.generate_content_stream = self.factory_function(
+ generate_content_stream, call_type="generate_content_stream"
+ )
+
def validate_fallbacks(self, fallback_param: Optional[List]):
"""
Validate the fallbacks parameter.
@@ -3230,6 +3252,10 @@ class Router:
"aimage_edit",
"allm_passthrough_route",
"alist_input_items",
+ "agenerate_content",
+ "generate_content",
+ "agenerate_content_stream",
+ "generate_content_stream",
] = "assistants",
):
"""
@@ -3240,7 +3266,7 @@ class Router:
- An asynchronous function for asynchronous call types
"""
# Handle synchronous call types
- if call_type == "responses":
+ if call_type in ("responses", "generate_content", "generate_content_stream"):
def sync_wrapper(
custom_llm_provider: Optional[
@@ -3285,6 +3311,8 @@ class Router:
"alist_files",
"aimage_edit",
"allm_passthrough_route",
+ "agenerate_content",
+ "agenerate_content_stream",
):
return await self._ageneric_api_call_with_fallbacks(
original_function=original_function,
diff --git a/litellm/utils.py b/litellm/utils.py
index 6fb9b3e8e30..8d151805352 100644
--- a/litellm/utils.py
+++ b/litellm/utils.py
@@ -6997,7 +6997,11 @@ class ProviderConfigManager:
return GoogleGenAIConfig()
elif litellm.LlmProviders.VERTEX_AI == provider:
- pass
+ from litellm.llms.vertex_ai.google_genai.transformation import (
+ VertexAIGoogleGenAIConfig,
+ )
+
+ return VertexAIGoogleGenAIConfig()
return None
diff --git a/tests/unified_google_tests/base_google_test.py b/tests/unified_google_tests/base_google_test.py
index 266ce28582f..c0bfd2c62b0 100644
--- a/tests/unified_google_tests/base_google_test.py
+++ b/tests/unified_google_tests/base_google_test.py
@@ -58,6 +58,7 @@ class BaseGoogleGenAITest:
text="Hello, can you tell me a short joke?"
)
],
+ role="user",
)
litellm._turn_on_debug()
@@ -93,6 +94,7 @@ class BaseGoogleGenAITest:
text="Hello, can you tell me a short joke?"
)
],
+ role="user",
)
print(f"Testing {'async' if is_async else 'sync'} streaming with model config: {request_params}")
@@ -102,18 +104,20 @@ class BaseGoogleGenAITest:
if is_async:
print("\n--- Testing async agenerate_content_stream ---")
- async for chunk in agenerate_content_stream(
+ response = await agenerate_content_stream(
contents=contents,
**request_params
- ):
+ )
+ async for chunk in response:
print(f"Async chunk: {chunk}")
chunks.append(chunk)
else:
print("\n--- Testing sync generate_content_stream ---")
- for chunk in generate_content_stream(
+ response = generate_content_stream(
contents=contents,
**request_params
- ):
+ )
+ for chunk in response:
print(f"Sync chunk: {chunk}")
chunks.append(chunk)
diff --git a/tests/unified_google_tests/test_vertex_ai_native.py b/tests/unified_google_tests/test_vertex_ai_native.py
new file mode 100644
index 00000000000..3dd40380375
--- /dev/null
+++ b/tests/unified_google_tests/test_vertex_ai_native.py
@@ -0,0 +1,10 @@
+from base_google_test import BaseGoogleGenAITest
+
+class TestVertexAIGenerateContent(BaseGoogleGenAITest):
+ """Test Vertex AI"""
+
+ @property
+ def model_config(self):
+ return {
+ "model": "vertex_ai/gemini-1.5-flash",
+ }
\ No newline at end of file