Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
mitchspano opened this issue Apr 16, 2024 · 7 comments
Assignees
Labels
component:python sdk Issue/PR related to Python SDK type:bug Something isn't working

Comments

@mitchspano
Copy link

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@

@mitchspano mitchspano added component:python sdk Issue/PR related to Python SDK type:bug Something isn't working labels Apr 16, 2024
@mitchspano mitchspano changed the title TypeError: argument of type 'Part' is not iterable - response.text is no longer directly accessible response.text is no longer directly accessible - TypeError: argument of type 'Part' is not iterable Apr 16, 2024
@singhniraj08 singhniraj08 added the status:triaged Issue/PR triaged to the corresponding sub-team label Apr 18, 2024
@laxman-munigala
Copy link

Any update on this pls. Does this break all the python examples?

@MarkDaoust
Copy link
Collaborator

The public python examples are okay, this is a google-internal problem.

@mitchspano I've added you to an email thread titled "Checking for oneof field presence in UPB proto messages", where we're discussing the cause of this.

@github-actions github-actions bot removed the status:triaged Issue/PR triaged to the corresponding sub-team label Apr 22, 2024
@laxman-munigala
Copy link

laxman-munigala commented Apr 22, 2024

Thanks @MarkDaoust .. I am getting below error using langchain aswell as google-cloud-aiplatform. Am i missing something.

image image

@MarkDaoust MarkDaoust reopened this Apr 22, 2024
@MarkDaoust
Copy link
Collaborator

MarkDaoust commented Apr 22, 2024

Interesting. Thanks for the update. Reopened.

Internally it has something to do with switching to upb protos, IDK if it's the same problem here.

https://github.com/protocolbuffers/upb?tab=readme-ov-file
https://github.com/protocolbuffers/protobuf/tree/main/upb

proto-plus (used by these libraries)depends on an older version of protobuf (<5, when latest is 5.26.1), but upgrading to 5.26 doesn't cause this error.

Can ou post a "pip freeze | grep proto"?

@laxman-munigala
Copy link

image

@MarkDaoust
Copy link
Collaborator

Just with the python versions, using this SDK I can't reproduce that.

Can you reproduce the error in Colab, for example, so we can replicate it abnd share with the owners?

@laxman-munigala
Copy link

Used below to create my environment where i see the issue.

name: python-test
channels:

  • defaults
    dependencies:
  • python
  • pip=23.3
  • requests=2.31
  • pandas=2.2
  • plotly=5.19
  • sqlalchemy=2.0
  • streamlit=1.32
  • fastapi=0.103
  • uvicorn=0.20
  • ipykernel=6.28
  • pip:
    • duckdb == 0.10
    • google-cloud-aiplatform
    • langchain
    • langchain-google-vertexai

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component:python sdk Issue/PR related to Python SDK type:bug Something isn't working
Projects
None yet
Development

No branches or pull requests

4 participants