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/regex/email.tentative.https.window.html - WPT Dashboard Interop Dashboard
// META: title=Language Model Response Regex - Email
// 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 = /^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$/;
const response = await session.prompt(
'Extract the email address from "You can reach me at foo@example.com"',
{responseConstraint: regex});
assert_true(typeof response === 'string');
assert_true(regex.test(response),
`Response "${response}" should match regex ${regex}`);
}, 'Prompt should work with an email regex constraint.');