Repository navigation
fix: accept Gemini candidates without generated content - #57
Conversation
|
@JDeepD is this PR still in progress or can it come out of draft status for review? |
Gemini can return a candidate with no content, an empty content object, or content without parts when nothing was generated, for example when thinking uses up the token limit or an image model returns NO_IMAGE. The parser rejected these with "Missing the candidates[0].content key", which broke image generation in the AI plugin. Such candidates are now parsed into an empty model message and the finish reason explains the outcome. Newer finish reasons are mapped (CONTINUATION to length, IMAGE_PROHIBITED_CONTENT, IMAGE_RECITATION and ESCALATION to content_filter), and any other value maps to error instead of throwing. Fixes WordPress#23
109265e to
545a7ab
Compare
|
The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message. To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. Props Bot commandsYou can trigger Props Bot actions by commenting on this PR:
|
|
@jeffpaul I've tested this with a free Gemini API key, which only has access to the text generation models. It fixes the I've marked this ready for review. Since #23 is about image generation, it would be great if @akshatkedia could confirm the fix with image models. Steps to deterministically reproduce the issue:
<?php
add_filter( 'wpai_image_generation_prompt_builder', static fn( $builder ) => $builder->using_max_tokens( 16 ) );
|
|
I've set up two WordPress Playground sites to make this easier to test. Both have the AI plugin with Image Generation and Title Generation turned on, plus two MU snippets that cap requests at 16 output tokens. Title Generation also uses Steps to reproduce:
|
superdav42
left a comment
There was a problem hiding this comment.
I tested and verified this is working. Thanks!
Gemini can return a candidate with no content, an empty content object, or content without parts when nothing was generated, for example when thinking uses up the token limit or an image model returns NO_IMAGE. The parser rejected these with "Missing the candidates[0].content key", which broke image generation in the AI plugin.
Such candidates are now parsed into an empty model message and the finish reason explains the outcome. Newer finish reasons are mapped (CONTINUATION to length, IMAGE_PROHIBITED_CONTENT, IMAGE_RECITATION and ESCALATION to content_filter), and any other value maps to error instead of throwing.
Fixes #23