tor-browser

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

language-model-quota-exceeded.tentative.https.window.js (1259B)


      1 // META: title=Language Model Quota Exceeded
      2 // META: script=/resources/testdriver.js
      3 // META: script=../resources/util.js
      4 // META: timeout=long
      5 
      6 'use strict';
      7 
      8 // Helper function to check that 'actual' is within 'expected +/- delta'.
      9 function isValueInRange(actual, expected, delta = 5) {
     10  const lowerBound = expected - delta;
     11  const upperBound = expected + delta;
     12  return actual >= lowerBound && actual <= upperBound;
     13 }
     14 
     15 promise_test(async t => {
     16  await ensureLanguageModel();
     17 
     18  // Start a new session to get the max tokens.
     19  const session = await createLanguageModel();
     20  const inputQuota = session.inputQuota;
     21  const initialPrompt = kTestPrompt.repeat(inputQuota);
     22  const measuredUsage = await session.measureInputUsage(initialPrompt);
     23 
     24  assert_greater_than(
     25      measuredUsage, inputQuota,
     26      'Measured usage should be greater than inputQuota');
     27 
     28  const promise = createLanguageModel(
     29      { initialPrompts: [ { role: "system", content: initialPrompt } ] });
     30  // Measured and actual usage may vary slightly for delimiter tokens.
     31  await promise_rejects_quotaexceedederror(t, promise, (actual) => {
     32    return isValueInRange(actual, measuredUsage);
     33  }, inputQuota);
     34 }, 'QuotaExceededError is thrown when initial prompts are too large.');