From 4b6dcfc8b1660df9ee9f84766d2e4a63eff170f9 Mon Sep 17 00:00:00 2001 From: Josh Postel Date: Wed, 21 May 2025 14:32:11 -0400 Subject: [PATCH 1/2] handle float --- libs/vertexai/langchain_google_vertexai/chat_models.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/libs/vertexai/langchain_google_vertexai/chat_models.py b/libs/vertexai/langchain_google_vertexai/chat_models.py index 17777517..552c9df4 100644 --- a/libs/vertexai/langchain_google_vertexai/chat_models.py +++ b/libs/vertexai/langchain_google_vertexai/chat_models.py @@ -308,6 +308,8 @@ def _convert_to_parts(message: BaseMessage) -> List[Part]: # error. if isinstance(raw_content, int): # type: ignore raw_content = str(raw_content) # type: ignore + if isinstance(raw_content, float): + raw_content = str(raw_content) if isinstance(raw_content, str): raw_content = [raw_content] result = [] From 0d4c0005ea71077b6cc1abd221278c16138f40b8 Mon Sep 17 00:00:00 2001 From: JoshuaPostel Date: Thu, 22 May 2025 09:11:16 -0400 Subject: [PATCH 2/2] suggested impl --- .../langchain_google_vertexai/chat_models.py | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/libs/vertexai/langchain_google_vertexai/chat_models.py b/libs/vertexai/langchain_google_vertexai/chat_models.py index 552c9df4..401506ca 100644 --- a/libs/vertexai/langchain_google_vertexai/chat_models.py +++ b/libs/vertexai/langchain_google_vertexai/chat_models.py @@ -303,15 +303,12 @@ def _convert_to_parts(message: BaseMessage) -> List[Part]: pass except ValueError: pass - # A linting error is thrown here because it does not think this line is - # reachable due to typing, but mypy is wrong so we ignore the lint - # error. - if isinstance(raw_content, int): # type: ignore - raw_content = str(raw_content) # type: ignore - if isinstance(raw_content, float): - raw_content = str(raw_content) - if isinstance(raw_content, str): - raw_content = [raw_content] + if isinstance(raw_content, (int, float, str)): + raw_content = [str(raw_content)] + elif isinstance(raw_content, list): + raw_content = [str(item) for item in raw_content] + else: + raise TypeError(f"Unsupported type: {type(raw_content)}") result = [] for raw_part in raw_content: part = _convert_to_prompt(raw_part)