Response.text raises an exception when only a function call is returned #532
Labels
component:python sdk
Issue/PR related to Python SDK
status:awaiting user response
Awaiting a response from the author
status:stale
Issue/PR will be closed automatically if there's no further activity
type:bug
Something isn't working
Description of the bug:
The
GenerateContentResponse.text
property sometimes raises an exception when no text is returned from the API. The documentation states that this property is equivalent toresponse.candidates[0].content.parts[0].text
, but accessing that property does not always raise an exception whenresponse.text
does. One of these cases is when the model responds by calling a function without any text, which leads to an error when parsing theparts
list.Actual vs expected behavior:
Minimal example:
Any other information you'd like to share?
Related Issues:
.text
accessor. #231response.text
quick accessor only works for simple (single-Part
) text responses. This response is not simple text.Use theresult.parts
accessor or the fullresult.candidates[index].content.parts
lookup instead. #170The text was updated successfully, but these errors were encountered: