diff --git a/autogen/oai/gemini.py b/autogen/oai/gemini.py index 28dcd28931ed..321feffe7f4a 100644 --- a/autogen/oai/gemini.py +++ b/autogen/oai/gemini.py @@ -501,7 +501,12 @@ def is_function_call(parts): # If this is first message or the role is different from the previous role then append the parts else: # If the previous text message is empty then update the text to "empty" as Gemini does not support empty messages - if (len(rst) > 0) and ("text" in rst[-1].parts[0]._raw_part) and (rst[-1].parts[0].text == ""): + if ( + (len(rst) > 0) + and hasattr(rst[-1].parts[0], "_raw_part") + and hasattr(rst[-1].parts[0]._raw_part, "text") + and (rst[-1].parts[0].text == "") + ): append_text_to_last("empty") append_parts(parts, role)