From 43319b562a4e2da5979a2b1c35548fa18ae498e7 Mon Sep 17 00:00:00 2001 From: Chesars Date: Sun, 22 Feb 2026 09:17:36 -0300 Subject: [PATCH] fix(lint): update return/yield types to ModelResponseStream - langgraph sse_iterator: update return types from ModelResponse to ModelResponseStream across all methods - bedrock agentcore: fix async generator yield type annotation - vertex gemini: add type: ignore for MyPy narrowing false positive --- .../llms/bedrock/chat/agentcore/transformation.py | 2 +- litellm/llms/langgraph/chat/sse_iterator.py | 14 +++++++------- .../gemini/vertex_and_google_ai_studio_gemini.py | 2 +- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/litellm/llms/bedrock/chat/agentcore/transformation.py b/litellm/llms/bedrock/chat/agentcore/transformation.py index b85a0b70f7..fe7d4b194a 100644 --- a/litellm/llms/bedrock/chat/agentcore/transformation.py +++ b/litellm/llms/bedrock/chat/agentcore/transformation.py @@ -601,7 +601,7 @@ class AmazonAgentCoreConfig(BaseConfig, BaseAWSLLM): self, response: httpx.Response, model: str, - ) -> AsyncGenerator[ModelResponse, None]: + ) -> AsyncGenerator[ModelResponseStream, None]: """ Internal async generator that parses SSE and yields ModelResponse chunks. """ diff --git a/litellm/llms/langgraph/chat/sse_iterator.py b/litellm/llms/langgraph/chat/sse_iterator.py index 8d946c4e52..cf81998055 100644 --- a/litellm/llms/langgraph/chat/sse_iterator.py +++ b/litellm/llms/langgraph/chat/sse_iterator.py @@ -11,7 +11,7 @@ from typing import TYPE_CHECKING, Optional import httpx from litellm._logging import verbose_logger -from litellm.types.utils import Delta, ModelResponse, ModelResponseStream, StreamingChoices +from litellm.types.utils import Delta, ModelResponseStream, StreamingChoices if TYPE_CHECKING: pass @@ -44,7 +44,7 @@ class LangGraphSSEStreamIterator: self.async_line_iterator = self.response.aiter_lines() return self - def _parse_sse_line(self, line: str) -> Optional[ModelResponse]: + def _parse_sse_line(self, line: str) -> Optional[ModelResponseStream]: """ Parse a single SSE line and return a ModelResponse chunk if applicable. @@ -71,7 +71,7 @@ class LangGraphSSEStreamIterator: return None - def _process_data(self, data) -> Optional[ModelResponse]: + def _process_data(self, data) -> Optional[ModelResponseStream]: """ Process parsed data from SSE stream. @@ -101,7 +101,7 @@ class LangGraphSSEStreamIterator: return None - def _process_messages_event(self, payload) -> Optional[ModelResponse]: + def _process_messages_event(self, payload) -> Optional[ModelResponseStream]: """ Process a messages event from the stream. @@ -128,7 +128,7 @@ class LangGraphSSEStreamIterator: return None - def _process_metadata_event(self, payload) -> Optional[ModelResponse]: + def _process_metadata_event(self, payload) -> Optional[ModelResponseStream]: """ Process a metadata event, which may signal the end of the stream. """ @@ -177,7 +177,7 @@ class LangGraphSSEStreamIterator: return chunk - def __next__(self) -> ModelResponse: + def __next__(self) -> ModelResponseStream: """Sync iteration - parse SSE events and yield ModelResponse chunks.""" try: if self.line_iterator is None: @@ -205,7 +205,7 @@ class LangGraphSSEStreamIterator: verbose_logger.error(f"Error in LangGraph SSE stream: {str(e)}") raise StopIteration - async def __anext__(self) -> ModelResponse: + async def __anext__(self) -> ModelResponseStream: """Async iteration - parse SSE events and yield ModelResponse chunks.""" try: if self.async_line_iterator is None: diff --git a/litellm/llms/vertex_ai/gemini/vertex_and_google_ai_studio_gemini.py b/litellm/llms/vertex_ai/gemini/vertex_and_google_ai_studio_gemini.py index cf3461a996..1783b5e630 100644 --- a/litellm/llms/vertex_ai/gemini/vertex_and_google_ai_studio_gemini.py +++ b/litellm/llms/vertex_ai/gemini/vertex_and_google_ai_studio_gemini.py @@ -2093,7 +2093,7 @@ class VertexGeminiConfig(VertexAIBaseConfig, BaseConfig): chat_completion_logprobs=chat_completion_logprobs, image_response=image_response, ) - model_response.choices.append(choice) + model_response.choices.append(choice) # type: ignore[arg-type] elif isinstance(model_response, ModelResponse): choice = litellm.Choices( finish_reason=VertexGeminiConfig._check_finish_reason(