Source code
Revision control
Copy as Markdown
Other Tools
Test Info: Warnings
- This test has a WPT meta file that expects 1 subtest issues.
- This WPT test may be referenced by the following Test IDs:
- /ai/language-model/response-constraint/json-schema/valid-schema-with-prefix-success.tentative.https.window.html - WPT Dashboard Interop Dashboard
// META: title=Language Model Response JSON Schema - Valid Schema With Prefix Success
// META: script=/resources/testdriver.js
// META: script=/resources/testdriver-vendor.js
// META: script=../../../resources/util.js
// META: timeout=long
'use strict';
promise_test(async t => {
await ensureLanguageModel();
const session = await createLanguageModel();
const goodPrefix = '{ "Rating": ';
const assistantResponse = await session.prompt(
[
{role: 'user', content: 'hello'},
{role: 'assistant', content: goodPrefix, prefix: true}
],
{responseConstraint: kValidResponseSchema});
const response = goodPrefix + assistantResponse;
testResponseJsonSchema(response, t);
}, 'Prompt should work when a valid response json schema and matching prefix is provided.');