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]
Python ai-gatewayanthropicazure-openaibedrockgatewaylangchainlitellmllmllm-gatewayllmopsmcp-gatewayopenaiopenai-proxyrustrust-aivertex-ai
fix mypy check issues
Henry Wang33218606b88c
diff --git a/litellm/google_genai/adapters/transformation.py b/litellm/google_genai/adapters/transformation.pyindex 2b3cce5084a..9d3f990b1aa 100644--- a/litellm/google_genai/adapters/transformation.py+++ b/litellm/google_genai/adapters/transformation.py@@ -9,6 +9,7 @@ from litellm.types.llms.openai import (ChatCompletionAssistantMessage,ChatCompletionAssistantToolCall,ChatCompletionRequest,+ ChatCompletionSystemMessage,ChatCompletionToolCallFunctionChunk,ChatCompletionToolChoiceValues,ChatCompletionToolMessage,@@ -33,7 +34,7 @@ class GoogleGenAIStreamWrapper(AdapterCompletionStreamWrapper):sent_first_chunk: bool = False# State tracking for accumulating partial tool calls- gccumulated_tool_calls: Dict[str, Dict[str, Any]]+ accumulated_tool_calls: Dict[str, Dict[str, Any]]def __init__(self, completion_stream: Any):self.sent_first_chunk = False@@ -373,7 +374,7 @@ class GoogleGenAIAdapter:system_parts = system_instruction.get("parts", [])if system_parts and "text" in system_parts[0]:messages.append(- ChatCompletionUserMessage(+ ChatCompletionSystemMessage(role="system", content=system_parts[0]["text"]))@@ -466,10 +467,7 @@ class GoogleGenAIAdapter:Returns:Dict in Google GenAI generate_content response format"""- if isinstance(response, AdapterCompletionStreamWrapper):- return self.translate_streaming_completion_to_generate_content(- response, wrapper=response- )+# Extract the main response contentchoice = response.choices[0] if response.choices else Nonediff --git a/litellm/main.py b/litellm/main.pyindex 37f9223afc0..c1a6a5d8c3f 100644--- a/litellm/main.py+++ b/litellm/main.py@@ -24,6 +24,7 @@ from functools import partialfrom typing import (TYPE_CHECKING,Any,+ AsyncIterator,Callable,Coroutine,Dict,@@ -5141,12 +5142,18 @@ async def aadapter_completion(async def aadapter_generate_content(**kwargs,-) -> Union[ModelResponse, CustomStreamWrapper]:+) -> Union[Dict[str, Any], AsyncIterator[bytes]]:from litellm.google_genai.adapters.handler import (GenerateContentToCompletionHandler,)- return await GenerateContentToCompletionHandler.async_generate_content_handler(**kwargs, _is_async=True)+ coro = cast(+ Coroutine[Any, Any, Union[Dict[str, Any], AsyncIterator[bytes]]],+ GenerateContentToCompletionHandler.generate_content_handler(+ **kwargs, _is_async=True+ ),+ )+ return await corodef adapter_completion(diff --git a/litellm/proxy/google_endpoints/endpoints.py b/litellm/proxy/google_endpoints/endpoints.pyindex 35c83f9ddb9..51c6d5ab634 100644--- a/litellm/proxy/google_endpoints/endpoints.py+++ b/litellm/proxy/google_endpoints/endpoints.py@@ -1,4 +1,4 @@-from fastapi import APIRouter, Depends, Request, Response+from fastapi import APIRouter, Depends, Request, Response, HTTPExceptionfrom fastapi.responses import StreamingResponsefrom litellm.proxy._types import *@@ -30,9 +30,9 @@ async def google_generate_content(data = await _read_request_body(request=request)if "model" not in data:data["model"] = model_name- data["stream"] = False-# call router+ if llm_router is None:+ raise HTTPException(status_code=500, detail="Router not initialized")response = await llm_router.agenerate_content(**data)return response@@ -61,6 +61,8 @@ async def google_stream_generate_content(data["stream"] = True # enforce streaming for this endpoint# call router+ if llm_router is None:+ raise HTTPException(status_code=500, detail="Router not initialized")response = await llm_router.agenerate_content(**data)# Check if response is an async iterator (streaming response)