Source code

Revision control

Copy as Markdown

Other Tools

Test Info: Warnings

// META: title=Language Model Response Regex - Enumeration
// 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 regex = /^(Red|Green|Blue)$/;
const response = await session.prompt(
'Extract the color from "The sky was clear and blue"',
{responseConstraint: regex});
assert_true(typeof response === 'string');
assert_true(regex.test(response),
`Response "${response}" should match regex ${regex}`);
}, 'Prompt should work with an enumeration regex constraint.');