From 74e4c2e81af66835491f71a3bfe6270e2b9e7a96 Mon Sep 17 00:00:00 2001 From: DH Date: Thu, 11 Jul 2024 14:10:20 +0800 Subject: [PATCH 1/2] fix: correct the Part argument is not iterable error --- google/generativeai/types/generation_types.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/google/generativeai/types/generation_types.py b/google/generativeai/types/generation_types.py index d4bed8b86..39c7996be 100644 --- a/google/generativeai/types/generation_types.py +++ b/google/generativeai/types/generation_types.py @@ -440,10 +440,10 @@ def text(self): texts = [] for part in parts: - if "text" in part: + if "text" in dir(part): texts.append(part.text) continue - if "executable_code" in part: + if "executable_code" in dir(part): language = part.executable_code.language.name.lower() if language == "language_unspecified": language = "" @@ -451,7 +451,7 @@ def text(self): language = f" {language}" texts.extend([f"```{language}", part.executable_code.code.lstrip("\n"), "```"]) continue - if "code_execution_result" in part: + if "code_execution_result" in dir(part): outcome_result = part.code_execution_result.outcome.name.lower().replace( "outcome_", "" ) From 6ea8e3a9168f82814730087736eac48b69bcda65 Mon Sep 17 00:00:00 2001 From: DH Date: Fri, 12 Jul 2024 12:44:30 +0800 Subject: [PATCH 2/2] fix: correct the Part argument is not iterable error more robustly --- google/generativeai/types/generation_types.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/google/generativeai/types/generation_types.py b/google/generativeai/types/generation_types.py index 39c7996be..d82610ed0 100644 --- a/google/generativeai/types/generation_types.py +++ b/google/generativeai/types/generation_types.py @@ -440,10 +440,10 @@ def text(self): texts = [] for part in parts: - if "text" in dir(part): + if hasattr(part, "text"): texts.append(part.text) continue - if "executable_code" in dir(part): + if hasattr(part, "executable_code"): language = part.executable_code.language.name.lower() if language == "language_unspecified": language = "" @@ -451,7 +451,7 @@ def text(self): language = f" {language}" texts.extend([f"```{language}", part.executable_code.code.lstrip("\n"), "```"]) continue - if "code_execution_result" in dir(part): + if hasattr(part, "code_execution_result"): outcome_result = part.code_execution_result.outcome.name.lower().replace( "outcome_", "" )