tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

language-model-availability-available.tentative.https.window.js (2669B)


      1 // META: title=Language Model Availability Available
      2 // META: script=/resources/testdriver.js
      3 // META: script=../resources/util.js
      4 // META: timeout=long
      5 
      6 'use strict';
      7 
      8 // These tests depend on some level of model availability, whereas those in
      9 // language-model-api-availability-available.https.window.js have no availability requirements.
     10 
     11 promise_test(async () => {
     12  await ensureLanguageModel();
     13 }, 'LanguageModel.availability() is available with no options');
     14 
     15 promise_test(async () => {
     16  await ensureLanguageModel();
     17  // An array of supported test option values.
     18  const kCreateOptionsSpec = [
     19    { topK: [1, 1.5, 2, 3, 99] },  // Nominally int 1-10+.
     20    { temperature: [0, 0.5, 1, 2] },  // Nominally float 0-1.
     21    { expectedInputs: [undefined, [], [{type: 'text'}], [{type: 'text', languages: ['en']}]] },
     22    { expectedOutputs: [undefined, [], [{type: 'text'}], [{type: 'text', languages: ['en']}]] },
     23  ];
     24  for (const options of generateOptionCombinations(kCreateOptionsSpec)) {
     25    const availability = await LanguageModel.availability(options);
     26    assert_in_array(availability, kValidAvailabilities, JSON.stringify(options));
     27  }
     28 }, 'LanguageModel.availability() returns available with supported options');
     29 
     30 promise_test(async () => {
     31  await ensureLanguageModel();
     32  // An array of unsupported test options.
     33  const kUnsupportedCreateOptions = [
     34    { expectedInputs: [{type: 'text', languages: ['unk']}] },  // Language not supported.
     35    { expectedOutputs: [{type: 'text', languages: ['unk']}] },  // Language not supported.
     36    { expectedOutputs: [{type: 'image'}] },  // Type not supported.
     37    { expectedOutputs: [{type: 'audio'}] },  // Type not supported.
     38    { topK: 0, temperature: 0.5 },  // zero topK not supported.
     39    { topK: -3, temperature: 0.5 },  // negative topK not supported.
     40    { topK: 3, temperature: -0.5 },  // negative temperature not supported.
     41    { topK: 3 },  // topK without temperature not supported.
     42    { temperature: 0.5 },  // temperature without topK not supported.
     43  ];
     44  for (const options of kUnsupportedCreateOptions) {
     45    assert_equals(await LanguageModel.availability(options), 'unavailable', JSON.stringify(options));
     46  }
     47 }, 'LanguageModel.availability() returns unavailable with unsupported options');
     48 
     49 promise_test(async t => {
     50  await ensureLanguageModel();
     51  // An array of invalid test options.
     52  const kInvalidCreateOptions = [
     53    { expectedInputs: [{type: 'soup'}] },  // Type not supported.
     54  ];
     55  for (const options of kInvalidCreateOptions) {
     56    await promise_rejects_js(t, TypeError, LanguageModel.availability(options));
     57  }
     58 }, 'LanguageModel.availability() rejects with invalid options');