Thanks to visit codestin.com
Credit goes to github.com

Skip to content

response.text is no longer directly accessible - TypeError: argument of type 'Part' is not iterable  #288

@mitchspano

Description

@mitchspano

Description of the bug:

Accessing the property response.text no longer works.

genai.configure(api_key = gcp_key)
model = genai.GenerativeModel("gemini-pro")
response = model.generate_content(prompt)

print(str(response.text)
# TypeError: argument of type 'Part' is not iterable
# google/generativeai/types/generation_types.py
# line 327, in text
#    if len(parts) != 1 or "text" not in parts[0]:

As a workaround, I can get the detail with response.candidates[0].content.parts[0].text, but this seems like it might be a breaking change?

Actual vs expected behavior:

I should be able to reference response.text directly.

Any other information you'd like to share?

NOTE: I am using the internal Google3 version of this SDK - see go/generative-ai-python-sdk-response-type-issue for the exact line internally. There seems to be a discrepancy between Google3 and GitHub - this is the line in the GitHub repo.

Feel free to reach out to me internally - mitchspano@

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions