From 849051102a6e315072e3a1d8dfdcee1527436c92 Mon Sep 17 00:00:00 2001 From: Erick Friis Date: Sat, 3 Feb 2024 17:45:44 -0800 Subject: [PATCH] google-genai[patch]: fix new core typing (#16988) --- .../google-genai/langchain_google_genai/chat_models.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/libs/partners/google-genai/langchain_google_genai/chat_models.py b/libs/partners/google-genai/langchain_google_genai/chat_models.py index 37cc5f342d689..d30990c5b6e4b 100644 --- a/libs/partners/google-genai/langchain_google_genai/chat_models.py +++ b/libs/partners/google-genai/langchain_google_genai/chat_models.py @@ -341,7 +341,9 @@ def _parse_chat_history( return messages -def _parts_to_content(parts: List[genai.types.PartType]) -> Union[List[dict], str]: +def _parts_to_content( + parts: List[genai.types.PartType], +) -> Union[str, List[Union[Dict[Any, Any], str]]]: """Converts a list of Gemini API Part objects into a list of LangChain messages.""" if len(parts) == 1 and parts[0].text is not None and not parts[0].inline_data: # Simple text response. The typical response @@ -349,7 +351,7 @@ def _parts_to_content(parts: List[genai.types.PartType]) -> Union[List[dict], st elif not parts: logger.warning("Gemini produced an empty response.") return "" - messages = [] + messages: List[Union[Dict[Any, Any], str]] = [] for part in parts: if part.text is not None: messages.append(