Hi,
I am trying to create a chat session and set a history node value in the request to GenerateContent.
Unfortunately whatever combination of values i would use would come back with the error
```
rpc error: code = InvalidArgument desc = Please ensure that multiturn requests alternate between user and model.
```
The history node value i put is:
```
[{"Role":"user","Parts":["something from the user"]}]
```
Any idea, what am i doing wrong?
Using Go.
Hi @arkadyb,
Welcome to Google Cloud Community!
The error message "rpc error: code = InvalidArgument desc = Please ensure that multiturn requests alternate between user and model" means that your provided history node is not formatted correctly for a multi-turn conversation.
Here's a breakdown of the issue and how to fix it:
The Problem:
The history node should represent a conversation with alternating turns from the user and the model. Your provided history only contains a single turn from the user
[{"Role":"user","Parts":["something from the user"]}]
The Solution:
You need to include both the user's and the model's previous turns in the history node. Each turn should be a separate object in the array, with the Role property set to either "user" or "model":
[
{"Role": "user", "Parts": ["something from the user in the previous turn"]},
{"Role": "model", "Parts": ["model's response to the previous turn"]},
{"Role": "user", "Parts": ["something from the user in the current turn"]}
]
By following these guidelines, you should be able to correctly format your history node for a multi-turn conversation and eliminate the "InvalidArgument" error.
I hope the above information is helpful.