diff --git a/google/generativeai/types/generation_types.py b/google/generativeai/types/generation_types.py index d4bed8b86..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 part: + if hasattr(part, "text"): texts.append(part.text) continue - if "executable_code" in 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 part: + if hasattr(part, "code_execution_result"): outcome_result = part.code_execution_result.outcome.name.lower().replace( "outcome_", "" )