Feat/@ai-sdk/google property ordering #6541
Open
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Background
Google's Generative AI API supports a
propertyOrdering
extension that allows developers to control the order of properties in structured JSON responses. This feature ensures consistent property ordering in generated objects, which is important for applications that require predictable output formats or when integrating with systems that depend on specific property sequences (for example CoT generation).Summary
This PR implements comprehensive support for Google's
propertyOrdering
feature in the AI SDK using a nested object configuration approach. The implementation provides fine-grained control over property ordering at all nesting levels.Key Features:
null
for leaf properties or nested configurationsgenerateObject()
andstreamObject()
Verification
I packaged the
@ai-sdk/google
package, installed it into a separate project and made several test runs with (and without) different configurations of the propertyOrdering parameter using streamObject() and logging the partialObjectStream into the console. The properties appeared in the specified order and appeared in another order when the propertyOrdering was not specified.I also used a temperature of 0 and a fixed seed for reproducible results, while leaving everything else (except the propertyOrdering) in place.
I tried different nesting levels, up to 5.
It is easy to test using code like this:
The output will be following:
Tasks
pnpm changeset
in the project root)pnpm prettier-fix
in the project root)Related Issues
Fixes #5879