generative-ai-docs
generative-ai-docs copied to clipboard
Missing `content` field when `finishReason` is other than `STOP`
Description of the bug:
when the Candidate.finishReason response field is not set to STOP, the Candidate.content is missing.
example reproduction
curl --request POST \
--header "Content-Type: application/json" \
--data '{"contents":[{"parts":[{"text":"hi!"}]}],"generationConfig":{"maxOutputTokens":1}}' \
https://generativelanguage.googleapis.com/v1/models/gemini-pro:generateContent?key=YOUR_API_KEY
Actual vs expected behavior:
the response to this request is currently
{
"candidates": [
{
"finishReason": "MAX_TOKENS",
"index": 0,
"safetyRatings": [...]
}
],
"promptFeedback": {
"safetyRatings": [...]
}
}
the candidates[0].content field is expected to contain the first generated token (as maxOutputTokens was set to 1), but is missing
Any other information you'd like to share?
this started happening between 2024-01-12 and 2024-01-14 on the v1beta API version
I have the same issue. Any updates?
@xslingcn you could use the streamGenerateContent endpoint and concatenate all returned parts (excluding the last one, which seems to be affected by the issue i described)
I also have the same issue. This makes the query from API very unstable, frequently resulting in null response. :(
same here. My response is: { "candidates": [ { "finishReason": "OTHER", "index": 0 } ], "usageMetadata": { "promptTokenCount": 171, "totalTokenCount": 171 } }