Skip to content

Commit fff6c17

Browse files
committed
Use "language model" instead of "assistant"
(Although we keep it for the "system"/"user"/"assistant" roles, as that's a de-facto standard.)
1 parent 6ac8736 commit fff6c17

File tree

1 file changed

+39
-39
lines changed

1 file changed

+39
-39
lines changed

README.md

Lines changed: 39 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -51,10 +51,10 @@ Both of these potential goals could pose challenges to interoperability, so we w
5151

5252
### Zero-shot prompting
5353

54-
In this example, a single string is used to prompt the API, which is assumed to come from the user. The returned response is from the assistant.
54+
In this example, a single string is used to prompt the API, which is assumed to come from the user. The returned response is from the language model.
5555

5656
```js
57-
const session = await ai.assistant.create();
57+
const session = await ai.languageModel.create();
5858

5959
// Prompt the model and wait for the whole result to come back.
6060
const result = await session.prompt("Write me a poem.");
@@ -69,17 +69,17 @@ for await (const chunk of stream) {
6969

7070
### System prompts
7171

72-
The assistant can be configured with a special "system prompt" which gives it the context for future interactions:
72+
The language model can be configured with a special "system prompt" which gives it the context for future interactions:
7373

7474
```js
75-
const session = await ai.assistant.create({
75+
const session = await ai.languageModel.create({
7676
systemPrompt: "Pretend to be an eloquent hamster."
7777
});
7878

7979
console.log(await session.prompt("What is your favorite food?"));
8080
```
8181

82-
The system prompt is special, in that the assistant will not respond to it, and it will be preserved even if the context window otherwise overflows due to too many calls to `prompt()`.
82+
The system prompt is special, in that the language model will not respond to it, and it will be preserved even if the context window otherwise overflows due to too many calls to `prompt()`.
8383

8484
If the system prompt is too large (see [below](#tokenization-context-window-length-limits-and-overflow)), then the promise will be rejected with a `"QuotaExceededError"` `DOMException`.
8585

@@ -88,7 +88,7 @@ If the system prompt is too large (see [below](#tokenization-context-window-leng
8888
If developers want to provide examples of the user/assistant interaction, they can use the `initialPrompts` array. This aligns with the common "chat completions API" format of `{ role, content }` pairs, including a `"system"` role which can be used instead of the `systemPrompt` option shown above.
8989

9090
```js
91-
const session = await ai.assistant.create({
91+
const session = await ai.languageModel.create({
9292
initialPrompts: [
9393
{ role: "system", content: "Predict up to 5 emojis as a response to a comment. Output emojis, comma-separated." },
9494
{ role: "user", content: "This is amazing!" },
@@ -119,13 +119,13 @@ Some details on error cases:
119119
In addition to the `systemPrompt` and `initialPrompts` options shown above, the currently-configurable options are [temperature](https://huggingface.co/blog/how-to-generate#sampling) and [top-K](https://huggingface.co/blog/how-to-generate#top-k-sampling). More information about the values for these parameters can be found using the `capabilities()` API explained [below](#capabilities-detection).
120120

121121
```js
122-
const customSession = await ai.assistant.create({
122+
const customSession = await ai.languageModel.create({
123123
temperature: 0.8,
124124
topK: 10
125125
});
126126

127-
const capabilities = await ai.assistant.capabilities();
128-
const slightlyHighTemperatureSession = await ai.assistant.create({
127+
const capabilities = await ai.languageModel.capabilities();
128+
const slightlyHighTemperatureSession = await ai.languageModel.create({
129129
temperature: Math.max(capabilities.defaultTemperature * 1.2, 1.0),
130130
});
131131

@@ -134,10 +134,10 @@ const slightlyHighTemperatureSession = await ai.assistant.create({
134134

135135
### Session persistence and cloning
136136

137-
Each assistant session consists of a persistent series of interactions with the model:
137+
Each language model session consists of a persistent series of interactions with the model:
138138

139139
```js
140-
const session = await ai.assistant.create({
140+
const session = await ai.languageModel.create({
141141
systemPrompt: "You are a friendly, helpful assistant specialized in clothing choices."
142142
});
143143

@@ -155,7 +155,7 @@ const result2 = await session.prompt(`
155155
Multiple unrelated continuations of the same prompt can be set up by creating a session and then cloning it:
156156

157157
```js
158-
const session = await ai.assistant.create({
158+
const session = await ai.languageModel.create({
159159
systemPrompt: "You are a friendly, helpful assistant specialized in clothing choices."
160160
});
161161

@@ -171,13 +171,13 @@ const session2 = await session.clone({ signal: controller.signal });
171171

172172
### Session destruction
173173

174-
An assistant session can be destroyed, either by using an `AbortSignal` passed to the `create()` method call:
174+
A language model session can be destroyed, either by using an `AbortSignal` passed to the `create()` method call:
175175

176176
```js
177177
const controller = new AbortController();
178178
stopButton.onclick = () => controller.abort();
179179

180-
const session = await ai.assistant.create({ signal: controller.signal });
180+
const session = await ai.languageModel.create({ signal: controller.signal });
181181
```
182182

183183
or by calling `destroy()` on the session:
@@ -225,7 +225,7 @@ Note that because sessions are stateful, and prompts can be queued, aborting a s
225225

226226
### Tokenization, context window length limits, and overflow
227227

228-
A given assistant 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:
228+
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:
229229

230230
```js
231231
console.log(`${session.tokensSoFar}/${session.maxTokens} (${session.tokensLeft} left)`);
@@ -243,7 +243,7 @@ Some notes on this API:
243243
* 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.
244244
* The counting process can be aborted by passing an `AbortSignal`, i.e. `session.countPromptTokens(promptString, { signal })`.
245245

246-
It's possible to send a prompt that causes the context window to overflow. That is, consider a case where `session.countPromptTokens(promptString) > session.tokensLeft` 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 assistant 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. 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 an `"QuotaExceededError"` `DOMException` and nothing will be removed.
246+
It's possible to send a prompt that causes the context window to overflow. That is, consider a case where `session.countPromptTokens(promptString) > session.tokensLeft` 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. 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 an `"QuotaExceededError"` `DOMException` and nothing will be removed.
247247

248248
Such overflows can be detected by listening for the `"contextoverflow"` event on the session:
249249

@@ -255,12 +255,12 @@ session.addEventListener("contextoverflow", () => {
255255

256256
### Capabilities detection
257257

258-
In all our above examples, we call `ai.assistant.create()` and assume it will always succeed.
258+
In all our above examples, we call `ai.languageModel.create()` and assume it will always succeed.
259259

260260
However, sometimes a language model needs to be downloaded before the API can be used. In such cases, immediately calling `create()` will start the download, which might take a long time. The capabilities API gives you insight into the download status of the model:
261261

262262
```js
263-
const capabilities = await ai.assistant.capabilities();
263+
const capabilities = await ai.languageModel.capabilities();
264264
console.log(capabilities.available);
265265
```
266266

@@ -284,7 +284,7 @@ The capabilities API also contains other information about the model:
284284
In cases where the model needs to be downloaded as part of creation, you can monitor the download progress (e.g. in order to show your users a progress bar) using code such as the following:
285285

286286
```js
287-
const session = await ai.assistant.create({
287+
const session = await ai.languageModel.create({
288288
monitor(m) {
289289
m.addEventListener("downloadprogress", e => {
290290
console.log(`Downloaded ${e.loaded} of ${e.total} bytes.`);
@@ -298,7 +298,7 @@ If the download fails, then `downloadprogress` events will stop being emitted, a
298298
<details>
299299
<summary>What's up with this pattern?</summary>
300300

301-
This pattern is a little involved. Several alternatives have been considered. However, asking around the web standards community it seemed like this one was best, as it allows using standard event handlers and `ProgressEvent`s, and also ensures that once the promise is settled, the assistant object is completely ready to use.
301+
This pattern is a little involved. Several alternatives have been considered. However, asking around the web standards community it seemed like this one was best, as it allows using standard event handlers and `ProgressEvent`s, and also ensures that once the promise is settled, the session object is completely ready to use.
302302

303303
It is also nicely future-extensible by adding more events and properties to the `m` object.
304304

@@ -318,7 +318,7 @@ partial interface WindowOrWorkerGlobalScope {
318318
319319
[Exposed=(Window,Worker), SecureContext]
320320
interface AI {
321-
readonly attribute AIAssistantFactory assistant;
321+
readonly attribute AILanguageModelFactory languageModel;
322322
};
323323
324324
[Exposed=(Window,Worker), SecureContext]
@@ -335,20 +335,20 @@ enum AICapabilityAvailability { "readily", "after-download", "no" };
335335
```
336336

337337
```webidl
338-
// Assistant
338+
// Language Model
339339
340340
[Exposed=(Window,Worker), SecureContext]
341-
interface AIAssistantFactory {
342-
Promise<AIAssistant> create(optional AIAssistantCreateOptions options = {});
343-
Promise<AIAssistantCapabilities> capabilities();
341+
interface AILanguageModelFactory {
342+
Promise<AILanguageModel> create(optional AILanguageModelCreateOptions options = {});
343+
Promise<AILanguageModelCapabilities> capabilities();
344344
};
345345
346346
[Exposed=(Window,Worker), SecureContext]
347-
interface AIAssistant : EventTarget {
348-
Promise<DOMString> prompt(DOMString input, optional AIAssistantPromptOptions options = {});
349-
ReadableStream promptStreaming(DOMString input, optional AIAssistantPromptOptions options = {});
347+
interface AILanguageModel : EventTarget {
348+
Promise<DOMString> prompt(DOMString input, optional AILanguageModelPromptOptions options = {});
349+
ReadableStream promptStreaming(DOMString input, optional AILanguageModelPromptOptions options = {});
350350
351-
Promise<unsigned long long> countPromptTokens(DOMString input, optional AIAssistantPromptOptions options = {});
351+
Promise<unsigned long long> countPromptTokens(DOMString input, optional AILanguageModelPromptOptions options = {});
352352
readonly attribute unsigned long long maxTokens;
353353
readonly attribute unsigned long long tokensSoFar;
354354
readonly attribute unsigned long long tokensLeft;
@@ -358,12 +358,12 @@ interface AIAssistant : EventTarget {
358358
359359
attribute EventHandler oncontextoverflow;
360360
361-
Promise<AIAssistant> clone(optional AIAssistantCloneOptions options = {});
361+
Promise<AILanguageModel> clone(optional AILanguageModelCloneOptions options = {});
362362
undefined destroy();
363363
};
364364
365365
[Exposed=(Window,Worker), SecureContext]
366-
interface AIAssistantCapabilities {
366+
interface AILanguageModelCapabilities {
367367
readonly attribute AICapabilityAvailability available;
368368
369369
// Always null if available === "no"
@@ -375,30 +375,30 @@ interface AIAssistantCapabilities {
375375
AICapabilityAvailability supportsLanguage(DOMString languageTag);
376376
};
377377
378-
dictionary AIAssistantCreateOptions {
378+
dictionary AILanguageModelCreateOptions {
379379
AbortSignal signal;
380380
AICreateMonitorCallback monitor;
381381
382382
DOMString systemPrompt;
383-
sequence<AIAssistantPrompt> initialPrompts;
383+
sequence<AILanguageModelPrompt> initialPrompts;
384384
[EnforceRange] unsigned long topK;
385385
float temperature;
386386
};
387387
388-
dictionary AIAssistantPrompt {
389-
AIAssistantPromptRole role;
388+
dictionary AILanguageModelPrompt {
389+
AILanguageModelPromptRole role;
390390
DOMString content;
391391
};
392392
393-
dictionary AIAssistantPromptOptions {
393+
dictionary AILanguageModelPromptOptions {
394394
AbortSignal signal;
395395
};
396396
397-
dictionary AIAssistantCloneOptions {
397+
dictionary AILanguageModelCloneOptions {
398398
AbortSignal signal;
399399
};
400400
401-
enum AIAssistantPromptRole { "system", "user", "assistant" };
401+
enum AILanguageModelPromptRole { "system", "user", "assistant" };
402402
```
403403

404404
### Instruction-tuned versus base models
@@ -423,7 +423,7 @@ To actually get a response back from the model given a prompt, the following pos
423423
3. Add an initial prompt to establish context. (This will not generate a response.)
424424
4. Execute a prompt and receive a response.
425425

426-
We've chosen to manifest these 3-4 stages into the API as two methods, `ai.assistant.create()` and `session.prompt()`/`session.promptStreaming()`, with some additional facilities for dealing with the fact that `ai.assistant.create()` can include a download step. Some APIs simplify this into a single method, and some split it up into three (usually not four).
426+
We've chosen to manifest these 3-4 stages into the API as two methods, `ai.languageModel.create()` and `session.prompt()`/`session.promptStreaming()`, with some additional facilities for dealing with the fact that `ai.languageModel.create()` can include a download step. Some APIs simplify this into a single method, and some split it up into three (usually not four).
427427

428428
### Stateless or session-based
429429

0 commit comments

Comments
 (0)