You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
* Update docs to explain renaming of API features
* Update formatting
* Update formatting
* add onquotaoverflow deprecation comment to idl
* add onquotaoverflow deprecation comment to idl
* languagemodel.oncontextwindowoverflow should be languagemodel.oncontextoverflow
* languagemodel.oncontextwindowoverflow should be languagemodel.oncontextoverflow
---------
Co-authored-by: Isaac Ahouma <iahouma@google.com>
Copy file name to clipboardExpand all lines: README.md
+33-16Lines changed: 33 additions & 16 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -45,7 +45,11 @@ The following are potential goals we are not yet certain of:
45
45
46
46
Both of these potential goals could pose challenges to interoperability, so we want to investigate more how important such functionality is to developers to find the right tradeoff.
47
47
48
-
### Deprecation Notice
48
+
### API Updates: Deprecations and Renaming
49
+
50
+
To improve API clarity, consistency, and address inconsistencies in parameter support across various models, the LanguageModel API has been updated.
51
+
52
+
**Deprecated Features:**
49
53
50
54
The following features of the LanguageModel API are **deprecated** and their functionality is now restricted to web extension contexts only:
51
55
@@ -56,6 +60,19 @@ The following features of the LanguageModel API are **deprecated** and their fun
56
60
57
61
These features may be completely removed in the future. This change is intended to simplify the API and address inconsistencies in parameter support across various models.
58
62
63
+
**Renamed Features:**
64
+
65
+
The following features have been renamed. The old names are now deprecated and will only function as aliases within Chrome Extension contexts:
66
+
67
+
| Old Name (Deprecated in Extensions, Removed in Web) | New Name (Available in All Contexts) |
**Note:** Developers using any of the deprecated features within an extension context will receive warnings in the DevTools Issues tab. These deprecated features and aliases may be completely removed in a future Chrome release.
75
+
59
76
## Examples
60
77
61
78
### Zero-shot prompting
@@ -339,7 +356,7 @@ The returned value will be a string that matches the input `RegExp`. If the user
339
356
340
357
If a value that is neither a `RegExp` object or a valid JSON schema object is given, the method will error with a `TypeError`.
341
358
342
-
By default, the implementation may include the schema or regular expression as part of the message sent to the underlying language model, which will use up some of the [input quota](#tokenization-context-window-length-limits-and-overflow). You can measure how much it will use up by passing the `responseConstraint` option to `session.measureInputUsage()`. If you want to avoid this behavior, you can use the `omitResponseConstraintInput` option. In such cases, it's strongly recommended to include some guidance in the prompt string itself:
359
+
By default, the implementation may include the schema or regular expression as part of the message sent to the underlying language model, which will use up some of the [context window](#tokenization-context-window-length-limits-and-overflow). You can measure how much it will use up by passing the `responseConstraint` option to `session.measureContextUsage()`. If you want to avoid this behavior, you can use the `omitResponseConstraintInput` option. In such cases, it's strongly recommended to include some guidance in the prompt string itself:
The promise returned by `append()` will reject if the prompt cannot be appended (e.g., too big, invalid modalities for the session, etc.), or will fulfill once the prompt has been validated, processed, and appended to the session.
431
448
432
-
Note that `append()` can also cause [overflow](#tokenization-context-window-length-limits-and-overflow), in which case it will evict the oldest non-system prompts from the session and fire the `"quotaoverflow"` event.
449
+
Note that `append()` can also cause [overflow](#tokenization-context-window-length-limits-and-overflow), in which case it will evict the oldest non-system prompts from the session and fire the `"contextoverflow"` event.
433
450
434
451
### Configuration of per-session parameters
435
452
@@ -577,18 +594,18 @@ Finally, note that if either prompting or appending has caused an [overflow](#to
577
594
578
595
### Tokenization, context window length limits, and overflow
579
596
580
-
A given language model session will have a maximum number of tokens it can process. Developers can check their current usage and progress toward that limit by using the following properties on the session object:
597
+
A given language model session will have a maximum number of tokens it can process. Developers can check their current context usage and progress toward that limit by using the following properties on the session object:
581
598
582
599
```js
583
-
console.log(`${session.inputUsage} tokens used, out of ${session.inputQuota} tokens available.`);
600
+
console.log(`${session.contextUsage} tokens used, out of ${session.contextWindow} tokens available.`);
584
601
```
585
602
586
-
To know how many tokens a prompt will consume, without actually processing it, developers can use the `measureInputUsage()` method. This method accepts the same input types as `prompt()`, including strings and multimodal input arrays:
603
+
To know how many tokens a prompt will consume, without actually processing it, developers can use the `measureContextUsage()` method. This method accepts the same input types as `prompt()`, including strings and multimodal input arrays:
{ type:"text", value:"My response to your critique:" },
@@ -601,23 +618,23 @@ Some notes on this API:
601
618
602
619
* We do not expose the actual tokenization to developers since that would make it too easy to depend on model-specific details.
603
620
* Implementations must include in their count any control tokens that will be necessary to process the prompt, e.g. ones indicating the start or end of the input.
604
-
* The counting process can be aborted by passing an `AbortSignal`, i.e. `session.measureInputUsage(promptString, { signal })`.
605
-
* We use the phrases "input usage" and "input quota" in the API, to avoid being specific to the current language model tokenization paradigm. In the future, even if we change paradigms, we anticipate some concept of usage and quota still being applicable, even if it's just string length.
621
+
* The counting process can be aborted by passing an `AbortSignal`, i.e. `session.measureContextUsage(promptString, { signal })`.
622
+
* We use the phrases "context usage" and "context window" in the API, to avoid being specific to the current language model tokenization paradigm. In the future, even if we change paradigms, we anticipate some concept of usage and context window still being applicable, even if it's just string length.
606
623
607
-
It's possible to send a prompt that causes the context window to overflow. That is, consider a case where `session.measureInputUsage(promptString) > session.inputQuota - session.inputUsage` before calling `session.prompt(promptString)`, and then the web developer calls `session.prompt(promptString)` anyway. In such cases, the initial portions of the conversation with the language model will be removed, one prompt/response pair at a time, until enough tokens are available to process the new prompt. The exception is the [system prompt](#system-prompts), which is never removed.
624
+
It's possible to send a prompt that causes the context window to overflow. That is, consider a case where `session.measureContextUsage(promptString) > session.contextWindow - session.contextUsage` before calling `session.prompt(promptString)`, and then the web developer calls `session.prompt(promptString)` anyway. In such cases, the initial portions of the conversation with the language model will be removed, one prompt/response pair at a time, until enough tokens are available to process the new prompt. The exception is the [system prompt](#system-prompts), which is never removed.
608
625
609
-
Such overflows can be detected by listening for the `"quotaoverflow"` event on the session:
626
+
Such overflows can be detected by listening for the `"contextoverflow"` event on the session:
610
627
611
628
```js
612
-
session.addEventListener("quotaoverflow", () => {
613
-
console.log("We've gone past the quota, and some inputs will be dropped!");
console.log("We've gone past the context window, and some inputs will be dropped!");
614
631
});
615
632
```
616
633
617
634
If it's not possible to remove enough tokens from the conversation history to process the new prompt, then the `prompt()` or `promptStreaming()` call will fail with a `QuotaExceededError` exception and nothing will be removed. This is a proposed new type of exception, which subclasses `DOMException`, and replaces the web platform's existing `"QuotaExceededError"``DOMException`. See [whatwg/webidl#1465](https://github.com/whatwg/webidl/pull/1465) for this proposal. For our purposes, the important part is that it has the following properties:
618
635
619
636
*`requested`: how many tokens the input consists of
620
-
*`quota`: how many tokens were available (which will be less than `requested`, and equal to the value of `session.inputQuota - session.inputUsage` at the time of the call)
637
+
*`context window`: how many tokens were available (which will be less than `requested`, and equal to the value of `session.contextWindow - session.contextUsage` at the time of the call)
621
638
622
639
### Multilingual content and expected input languages
0 commit comments