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

Start chat with context

 

 

model = GenerativeModel("gemini-1.0-pro", generation_config={"temperature": 0}, tools=[retail_tool])
context = [
    Content(role = "user", parts = [
      Part(text = "System prompt: You are an assistent who can process json and answers off that."),
      Part(text = f"json is provided here {json.dumps(data)}")
    ]),
    Content(role = "model", parts = [Part(text = "understood")])
]
chat2 = model.start_chat(history = context)
 

 

I am not able to provide history to start chat conversation. Getting following error:

ValueError: history must be a list of Content objects.
 
I am passing content object in the array but its not happy. Ideally this method should have accepted a list of dict anyways to keep it simple.  Any idea how to solve it?
2 2 1,366
2 REPLIES 2

Hi,

May I know the documentation that you are following?

Thanks!

you have to use the `Part.from_text("str")` APIs

```

items.append(
Content(
role="user",
parts=[Part.from_text(message)],
)
)
```
 
(what an awful forum text editor this is)