feat(ai): honor responseJsonSchema in chrome adapter#9900
feat(ai): honor responseJsonSchema in chrome adapter#9900ryanwilson wants to merge 1 commit intomainfrom
Conversation
|
There was a problem hiding this comment.
Code Review
This pull request introduces support for responseJsonSchema in the ChromeAdapterImpl by mapping it to the responseConstraint parameter for both standard and streaming content generation. It also includes unit tests to verify that the configuration is correctly passed to the underlying language model. Feedback suggests refactoring the duplicated mapping logic into a private helper method and extending support to the responseSchema field for better parity with cloud backends.
| const promptOptions = { ...this.onDeviceParams.promptOptions }; | ||
| if (request.generationConfig?.responseJsonSchema) { | ||
| promptOptions.responseConstraint = request.generationConfig.responseJsonSchema; | ||
| } |
There was a problem hiding this comment.
The logic for merging generationConfig.responseJsonSchema into promptOptions is duplicated in both generateContent and generateContentStream (lines 183-186). This logic should be refactored into a private helper method to improve maintainability and ensure consistency as more configuration fields are mapped in the future.
| if (request.generationConfig?.responseJsonSchema) { | ||
| promptOptions.responseConstraint = request.generationConfig.responseJsonSchema; | ||
| } |
There was a problem hiding this comment.
While this PR correctly adds support for responseJsonSchema, the adapter currently ignores responseSchema from generationConfig. For better parity with the cloud backend and to support users using the Schema builder, consider also mapping responseSchema to responseConstraint if it is a plain object (i.e., SchemaRequest).
This PR adds support for structured JSON output in the Chrome on-device adapter by honoring the responseJsonSchema configuration.
Changes:
ChromeAdapterImplinpackages/ai/src/methods/chrome-adapter.tsto maprequest.generationConfig.responseJsonSchemato theresponseConstraintoption when calling the Chrome Prompt API (promptandpromptStreaming).chrome-adapter-browser.test.tsto verify that the schema is correctly passed through to the underlying browser API.