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

fix: correct the Part argument is not iterable error #453

Closed
wants to merge 2 commits into from

Conversation

DaHui-BT
Copy link

@DaHui-BT DaHui-BT commented Jul 11, 2024

Description of the change

I have changed the generation_types.py file. The changed line at [443, 446, 454]. Turn the part into dir(part)

Motivation

When using this library like:

response = genai.GenerativeModel('gemini-pro').generate_content("test",)
print(response.text)

the following error has occur:

File google\generativeai\types\generation_types.py:443, in BaseGenerateContentResponse.text(self)
    [441](google/generativeai/types/generation_types.py:441) texts = []
    [442](google/generativeai/types/generation_types.py:442) for part in parts:
--> [443](google/generativeai/types/generation_types.py:443)     if "text" in part:
    [444](google/generativeai/types/generation_types.py:444)         texts.append(part.text)
    [445](google/generativeai/types/generation_types.py:445)         continue

TypeError: argument of type 'Part' is not iterable

Type of change

Bug fix

Checklist

  • I have performed a self-review of my code.
  • I have verified that my change does not break existing code.
  • My PR is based on the latest changes of the main branch (if unsure, please run git pull --rebase upstream main).
  • I am familiar with the Google Style Guide for the language I have coded in.

Copy link

google-cla bot commented Jul 11, 2024

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

@github-actions github-actions bot added status:awaiting review PR awaiting review from a maintainer component:python sdk Issue/PR related to Python SDK labels Jul 11, 2024
@MarkDaoust
Copy link
Collaborator

#288

Thanks, but I don't think this is the right fix.

AFAIKT Something in your setup is breaking the proto-plus library, and is returning the proto instances without their proto-plus wrappers.

Your change fixes the first immediate symptom, but the code is littered with isinstance checks that won't see the expected proto-plus classes, and will do the wrong thing.

The last coment on #288 says they can reproduce this in anaconda.

Are you using anaconda?

@DaHui-BT
Copy link
Author

DaHui-BT commented Jul 12, 2024

Yes, I'm using miniconda.
I make a new commit with changes for turning the dir(part, attr) into hasattr(part, attr) which can just focus on using attribute checks.

@MarkDaoust
Copy link
Collaborator

I think this is the fix we need:
googleapis/proto-plus-python#471

@DaHui-BT DaHui-BT closed this Jul 15, 2024
@github-actions github-actions bot removed the status:awaiting review PR awaiting review from a maintainer label Jul 15, 2024
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
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants