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

function_call not handled in BaseGenerateContentResponse.text #620

Open neilp9 opened 1 week ago

neilp9 commented 1 week ago

Description of the bug:

calling session.send_message returns a GenerateContentResponse object, and when this response includes a function call, response.text raises the following error:

File ".../.virtualenvs/cai/lib/python3.11/site-packages/google/generativeai/types/generation_types.py", line 538, in text
    part_type = protos.Part.pb(part).whichOneof("data")
                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
AttributeError: whichOneof

Actual vs expected behavior:

response.text should return the text part of the response rather than throwing error. Related but separate of an issue, there should ideally be a convenience accessor for response.function_call

Any other information you'd like to share?

No response