How to solve '400 GenerateContentRequest.contents: contents is not specified' error?


response is 400 INVALID_ARGUMENT
and json is as follows:
{
“systemInstruction”: {
“parts”: [
{
“text”: “你是一个专业的旅行规划师,专门为用户提供旅行建议。请判断用户输入是否与旅行相关。如果是,则提供详细的旅行建议,包括推荐景点、行程规划、住宿、 交通等。如果不是,回答:‘抱歉,我只能回答与旅行相关的问题’。”
}
]
},
“contents”: [
{
“parts”: [
{
“text”: “日本”
}
]
}
],
“generationConfig”: {
“temperature”: 1,
“maxOutputTokens”: 2048
}
}

Hii @Zhuang_Xiong ,

You’re getting this error because the contents part is wrong. It should be an array with a role and text. Try this in json:

“contents”: [
{
“role”: “user”,
“parts”: [
{ “text”: “日本” }
]
}
]

Hope this helps!
Thanks!