I am trying to migrate my Gemini project from Google-generative-ai to Vertex AI. However, I ran into this error:
TypeError: Parameter to MergeFrom() must be instance of same class: expected <class 'Part'> got <class 'str'>.
My code essentially uses a stateless multi-turn conversation, just like here in the example at their documentation.
messages.append({'role':'model',
'parts':[response.text]})
messages.append({'role':'user',
'parts':["Okay, how about a more detailed explanation to a high school student?"]})
response = model.generate_content(messages)
to_markdown(response.text)
When trying it at Vertex AI however, it ran into the above error. The documentation provided by Google isn’t helping, instead using the chat function over the stateless conversation.
Is there any way to keep the stateless message handling for chat in Vertex AI, or do I have to convert to the chat method?
Help would be appreciated, thank you!
Here’s an example of how my code looks like. This works under GenAI/Gemini.:
messages = [
{
"role": "user",
"parts": [get_system_prompt(bytes_data)]
},
{
"role": "model",
"parts": ["Hi, I'm Q, your SQL Query Building Helper. Let's get started."]
}
]
messages.append({"role": "user", "parts": [prompt]})
model.generate_content(messages)
This is the result when I run under Vertex AI.
TypeError: Parameter to MergeFrom() must be instance of same class: expected <class 'Part'> got <class 'str'>.
Miguel Adarlo is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.