Fix missing input and output modality combinations, fixing usage of Nano Banana (among other problems)#11
Conversation
…ano Banana (among other problems).
|
The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the 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. |
|
Overall, this looks good. I noticed a nearly identical fix in WordPress/ai-provider-for-openai#11. I assume it's something every provider might need, so having a utility that simplifies configuration could help. I was thinking about using binary representation for optional modalities (not tested, but it should illustrate the idea): /**
* Build all modality combinations that always include the required modalities
* with every possible subset of the optional modalities.
*
* @param array $required Required modalities included in every combination.
* @param array $optional Optional modalities to generate subsets from.
* @return array List of modality combinations.
*/
function build_modality_combinations( $required, $optional ) {
$combinations = array();
$count = count( $optional );
for ( $i = 0; $i < ( 1 << $count ); $i++ ) {
$combo = $required;
for ( $j = 0; $j < $count; $j++ ) {
if ( $i & ( 1 << $j ) ) {
$combo[] = $optional[ $j ];
}
}
$combinations[] = $combo;
}
return $combinations;
}Example usage: $allModalityCombinationsWithText = build_modality_combinations(
array( ModalityEnum::text() ),
array( ModalityEnum::image(), ModalityEnum::audio(), ModalityEnum::document() )
);
$allModalityCombinationsTextAudio = build_modality_combinations(
array(),
array( ModalityEnum::text(), ModalityEnum::audio() )
); |
|
@gziolo Thank you! I opened WordPress/php-ai-client#215 to introduce such a helper, great idea. For now I'm going to proceed as is, and we can revise this once the helper has been released. |
Fixes #10
Great catch @dkotter! This pointed me to other similar omissions (which were probably less critical, but still could cause expected features to not work).