-
Notifications
You must be signed in to change notification settings - Fork 345
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
TypeError: argument of type 'Part' is not iterable
#3129
Comments
@Naznouz Please use |
|
I wasn't able to recreate the issue with:
Can you provide the closest Pypi version for the dependencies that are installed from local paths? |
@Naznouz This error is a bit puzzling. Could you please check the type of the raw part: print(type(response.candidates[0].content.parts[0]._raw_part)) |
Here is the result import vertexai
from vertexai.preview.generative_models import GenerativeModel # , Part
def generate():
"""Generates text using the Generative Model."""
# Initialize Vertex AI
vertexai.init(project="upgradecode", location="us-central1")
model = GenerativeModel("gemini-pro")
responses = model.generate_content(
"""hi. I would like to know the 10 first items of the fibonacci
sequence.""",
generation_config={
"max_output_tokens": 2048,
"temperature": 0.9,
"top_p": 1
},
stream=True,
)
for i, response in enumerate(responses):
print("Response `content.parts`:", i)
print(response.candidates[0].content.parts)
# print(repr(response.candidates[0].content.parts[0]).split("\"")[1])
print("Response `content._raw_part`:")
print(response.candidates[0].content.parts[0]._raw_part)
print("Response `content.text`:")
print(response.candidates[0].content.parts[0].text)
generate() Result:
May be some additional information that would help: I'm using a conda environment and here is the list of $ pip freeze | grep proto
googleapis-common-protos @ file:///Users/ec2-user/ci_py311/googleapis-common-protos-feedstock_1678326429456/work
proto-plus==1.23.0
protobuf==3.20.3 $ conda list proto
# packages in environment at /xxx/xxx/anaconda3:
#
# Name Version Build Channel
googleapis-common-protos 1.60.0 pypi_0 pypi
googleapis-common-protos-grpc 1.56.4 py311hecd8cb5_0
libprotobuf 3.20.3 hfff2838_0
proto-plus 1.23.0 pypi_0 pypi
protobuf 4.24.1 pypi_0 pypi |
I have made another test using a virtual env and it was fine. $ conda list google
# packages in environment at /xxx/xxx/anaconda3:
#
# Name Version Build Channel
google-api-core 2.11.1 pypi_0 pypi
google-api-core-grpc 2.10.1 py311hecd8cb5_0
google-api-python-client 2.97.0 pypi_0 pypi
google-auth 2.25.2 pypi_0 pypi
google-auth-httplib2 0.1.0 pypi_0 pypi
google-cloud-aiplatform 1.38.0 pypi_0 pypi
google-cloud-bigquery 3.14.0 pypi_0 pypi
google-cloud-bigquery-core 3.14.1 pyhd8ed1ab_1 conda-forge
google-cloud-core 2.4.1 pypi_0 pypi
google-cloud-resource-manager 1.11.0 pypi_0 pypi
google-cloud-storage 2.14.0 pypi_0 pypi
google-crc32c 1.5.0 py311h6c40b1e_0
google-resumable-media 2.7.0 pypi_0 pypi
googleapis-common-protos 1.60.0 pypi_0 pypi
googleapis-common-protos-grpc 1.56.4 py311hecd8cb5_0
grpc-google-iam-v1 0.13.0 pyhd8ed1ab_0 conda-forge |
Do you still have any environment where the issue reproduces? I'd be happy to investigate and fix it.
|
I get the same error, by just executing the python code from the playground in my google cloud shell. |
@Naznouz What does |
@chrissie303 What does |
I believe that it worked on Colab, because it is not based on "Conda" environment, like my case. $ pip freeze | grep google and $ pip freeze | grep proto |
Same problem here. I have Anaconda, so it is probably related to that.
and
|
I had to do |
check the link google-gemini/generative-ai-python#196 (comment) , i was able to solve that issue. You cannot directly access the text from the response. |
If "text" not in self.raw_part |
I've tried to reproduce this using Anaconda and could not repro:
Packages:
|
Thank you for your patience. Can you please test what does the following print on your systems?
Here is what it prints for me:
|
@Ark-kun I dont have the latest code base and i get this response for print commands: it prints |
hi, I had the same issue and fixed it by creating brand new conda env with new |
I'm not sure what's happening here. At east in @nikhil2406 case, it looks like the actual class of Here are the expected types:
@parthea Do you have any idea what could be happening here? |
@Ark-kun I also haven't been able to reproduce this issue. It sounds like it is specific to anaconda only. If anyone is able to share a |
I reproduced this issue on my workstation. I installed SDK using
or
|
Please can you clarify if you also see this problem on protobuf 4.x when you set the |
Is "protobuf 4.x" a typo? protobuf 4.x is already upb and |
When we execute the code from the test playground for Gemini in Vertex AI Studio, there is a type error. Actually,
_raw_part
is not a dict. It is of typePart
, as an extension ofproto.Message
. So, thetext
property of the classPart
is not available as keyword...I have found no way to extract text from a streaming response other than using
repr
function and trimming it.Environment details
MacOS Sonoma 14.2
3.11.5
23.2.1
google-cloud-aiplatform
version:Steps to reproduce
gcloud
Code example
Stack trace
The text was updated successfully, but these errors were encountered: