google-gemini / generative-ai-python

The official Python library for the Google Gemini API
https://pypi.org/project/google-generativeai/
Apache License 2.0
1.62k stars 322 forks source link

AttributeError: Unknown field for Candidate: finish_message. Did you mean: 'finish_reason'? #598

Closed allenporter closed 1 month ago

allenporter commented 1 month ago

Description of the bug:

When calling .text on the response it may fail with an AttributeError:

yaml_content = _parse_model_response(response.text)
^^^^^^^^^^^^^
File "/usr/local/lib/python3.12/site-packages/google/generativeai/types/generation_types.py", line 476, in text
if candidate.finish_message:
^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.12/site-packages/proto/message.py", line 906, in __getattr__
raise AttributeError(
AttributeError: Unknown field for Candidate: finish_message. Did you mean: 'finish_reason'?

Actual vs expected behavior:

No response

Any other information you'd like to share?

This appears to be lines recently changed in https://github.com/google-gemini/generative-ai-python/pull/527

Hamza-nabil commented 1 month ago

Upgrading may resolve the problem:

pip install -U google-generativeai

This issue(see https://github.com/google-gemini/generative-ai-python/issues/559)) is fixed in v0.8.3.

allenporter commented 1 month ago

Thanks, I thought I was on latest but must have been mistaken, and didn't see that in an issue search, thanks.