Get hands-on experience with 20+ free Google Cloud products and $300 in free credit for new customers.

Error when trying to access/print response from vertexai gemini-pro

I am encountering a hillarious error, working in google cloud shell, trying to query gemini-pro vertexai (genai currently not accessible for europeans...!).

I am just taking the python code created by the testbed,

and try to run it in a python file in google cloud shell.

When trying to print the response (print(response.text, end="")) I just get an error:

It produces the error: 

"Exception has occurred: TypeError
argument of type 'Part' is not iterable
print(response.text, end="")"

Here is the code:

 

import vertexai
from vertexai.preview.generative_models import GenerativeModel, Part

def generate():
  model = GenerativeModel("gemini-pro")
  responses = model.generate_content(
    """in which country is new york?""",
    generation_config={
        "max_output_tokens": 2048,
        "temperature": 0.9,
        "top_p": 1
    },
    safety_settings=[],
  stream=True,
  )
 
  for response in responses:
      print(response.text, end="")


generate()
 
When I am further analyzing this, I get more info, but still can not access the response text:

response.candidates: candidate.content: 
role: "model" parts {  text: "United States" }
candidate.content.parts:  [text: "United States" ]
candidate.content.parts[0]:
text: "United States"
type(candidate.content.parts[0])
<class 'vertexai.generative_models._generative_models.Part'>

I guess this is a bug that only  occurrs in my "unique" environment in google cloud shell. How can I solve this? 

Of course exactly the same code runs perfectly fine in the colab.

How could I completely reset the google cloud shell? (I guess the problem is a collision with some other package there).

1 5 6,905
5 REPLIES 5