-
Notifications
You must be signed in to change notification settings - Fork 402
Closed
googleapis/proto-plus-python
#475Labels
api: vertex-aiIssues related to the googleapis/python-aiplatform API.Issues related to the googleapis/python-aiplatform API.

Description
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 type Part
, as an extension of proto.Message
. So, the text
property of the class Part
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
- OS type and version:
MacOS Sonoma 14.2
- Python version:
3.11.5
- pip version:
23.2.1
google-cloud-aiplatform
version:
Name: google-cloud-aiplatform
Version: 1.38.1
Summary: Vertex AI API client library
Home-page: https://github.com/googleapis/python-aiplatform
Author: Google LLC
Author-email: [email protected]
License: Apache 2.0
Location: /Users/xxxxxxx/anaconda3/lib/python3.11/site-packages
Requires: google-api-core, google-cloud-bigquery, google-cloud-resource-manager, google-cloud-storage, packaging, proto-plus, protobuf, shapely
Required-by:
Steps to reproduce
- Just execute the example code below, after logging with
gcloud
Code example
import vertexai
from vertexai.preview.generative_models import GenerativeModel # , Part
def generate():
"""Generates text using the Generative Model."""
# Initialize Vertex AI
vertexai.init(project="<project_id>", 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:", i)
print(response.candidates[0].content.parts)
# print(repr(response.candidates[0].content.parts[0]).split("\"")[1])
print(response.candidates[0].content.parts[0].text)
generate()
Stack trace
Response: 0
[text: "1. 0\n2. 1\n3. 1\n4"
]
Traceback (most recent call last):
File "/Users/xxxxxxxxx/Documents/002-git/dolibarr-invoice/services.py", line 57, in <module>
generate()
File "/Users/xxxxxxxxx/Documents/002-git/dolibarr-invoice/services.py", line 54, in generate
print(response.candidates[0].content.parts[0].text)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/xxxxxxxxx/anaconda3/lib/python3.11/site-packages/vertexai/generative_models/_generative_models.py", line 1508, in text
if "text" not in self._raw_part:
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
TypeError: argument of type 'Part' is not iterable
SnailWhb and jemoncadar
Metadata
Metadata
Labels
api: vertex-aiIssues related to the googleapis/python-aiplatform API.Issues related to the googleapis/python-aiplatform API.