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
Copy file name to clipboardExpand all lines: README.md
+39-39Lines changed: 39 additions & 39 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -51,10 +51,10 @@ Both of these potential goals could pose challenges to interoperability, so we w
51
51
52
52
### Zero-shot prompting
53
53
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.
55
55
56
56
```js
57
-
constsession=awaitai.assistant.create();
57
+
constsession=awaitai.languageModel.create();
58
58
59
59
// Prompt the model and wait for the whole result to come back.
60
60
constresult=awaitsession.prompt("Write me a poem.");
@@ -69,17 +69,17 @@ for await (const chunk of stream) {
69
69
70
70
### System prompts
71
71
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:
73
73
74
74
```js
75
-
constsession=awaitai.assistant.create({
75
+
constsession=awaitai.languageModel.create({
76
76
systemPrompt:"Pretend to be an eloquent hamster."
77
77
});
78
78
79
79
console.log(awaitsession.prompt("What is your favorite food?"));
80
80
```
81
81
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()`.
83
83
84
84
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`.
85
85
@@ -88,7 +88,7 @@ If the system prompt is too large (see [below](#tokenization-context-window-leng
88
88
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.
89
89
90
90
```js
91
-
constsession=awaitai.assistant.create({
91
+
constsession=awaitai.languageModel.create({
92
92
initialPrompts: [
93
93
{ role:"system", content:"Predict up to 5 emojis as a response to a comment. Output emojis, comma-separated." },
94
94
{ role:"user", content:"This is amazing!" },
@@ -119,13 +119,13 @@ Some details on error cases:
119
119
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).
@@ -225,7 +225,7 @@ Note that because sessions are stateful, and prompts can be queued, aborting a s
225
225
226
226
### Tokenization, context window length limits, and overflow
227
227
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:
* 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.
244
244
* The counting process can be aborted by passing an `AbortSignal`, i.e. `session.countPromptTokens(promptString, { signal })`.
245
245
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.
247
247
248
248
Such overflows can be detected by listening for the `"contextoverflow"` event on the session:
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.
259
259
260
260
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:
@@ -284,7 +284,7 @@ The capabilities API also contains other information about the model:
284
284
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:
285
285
286
286
```js
287
-
constsession=awaitai.assistant.create({
287
+
constsession=awaitai.languageModel.create({
288
288
monitor(m) {
289
289
m.addEventListener("downloadprogress", e=> {
290
290
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
298
298
<details>
299
299
<summary>What's up with this pattern?</summary>
300
300
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.
302
302
303
303
It is also nicely future-extensible by adding more events and properties to the `m` object.
@@ -423,7 +423,7 @@ To actually get a response back from the model given a prompt, the following pos
423
423
3. Add an initial prompt to establish context. (This will not generate a response.)
424
424
4. Execute a prompt and receive a response.
425
425
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).
0 commit comments