Skip to content

Commit e91269e

Browse files
committed
Create a skeleton specification
It contains IDL and boilerplate for now.
1 parent 618d4e5 commit e91269e

File tree

6 files changed

+193
-113
lines changed

6 files changed

+193
-113
lines changed

.github/dependabot.yml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# See the documentation at
2+
# https://docs.github.com/github/administering-a-repository/configuration-options-for-dependency-updates
3+
version: 2
4+
updates:
5+
# Update actions used by .github/workflows in this repository.
6+
- package-ecosystem: "github-actions"
7+
directory: "/"
8+
schedule:
9+
interval: "weekly"
10+
groups:
11+
actions-org: # Groups all Github-authored actions into a single PR.
12+
patterns: ["actions/*"]

.github/workflows/auto-publish.yml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
name: CI
2+
on:
3+
pull_request: {}
4+
push:
5+
branches: [main]
6+
jobs:
7+
main:
8+
name: Build, Validate and Deploy
9+
runs-on: ubuntu-latest
10+
permissions:
11+
contents: write
12+
steps:
13+
- uses: actions/checkout@v4
14+
- uses: w3c/spec-prod@v2
15+
with:
16+
GH_PAGES_BRANCH: gh-pages
17+
BUILD_FAIL_ON: warning

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
index.html

.pr-preview.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"src_file": "index.bs",
3+
"type": "bikeshed",
4+
"params": {
5+
"force": 1
6+
}
7+
}
8+

README.md

Lines changed: 0 additions & 113 deletions
Original file line numberDiff line numberDiff line change
@@ -685,119 +685,6 @@ Finally, note that there is a sort of precedent in the (never-shipped) [`FetchOb
685685

686686
## Detailed design
687687

688-
### Full API surface in Web IDL
689-
690-
```webidl
691-
[Exposed=Window, SecureContext]
692-
interface LanguageModel : EventTarget {
693-
static Promise<LanguageModel> create(optional LanguageModelCreateOptions options = {});
694-
static Promise<Availability> availability(optional LanguageModelCreateCoreOptions options = {});
695-
static Promise<LanguageModelParams?> params();
696-
697-
// These will throw "NotSupportedError" DOMExceptions if role = "system"
698-
Promise<DOMString> prompt(
699-
LanguageModelPrompt input,
700-
optional LanguageModelPromptOptions options = {}
701-
);
702-
ReadableStream promptStreaming(
703-
LanguageModelPrompt input,
704-
optional LanguageModelPromptOptions options = {}
705-
);
706-
Promise<undefined> append(
707-
LanguageModelPrompt input,
708-
optional LanguageModelAppendOptions options = {}
709-
);
710-
711-
Promise<double> measureInputUsage(
712-
LanguageModelPrompt input,
713-
optional LanguageModelPromptOptions options = {}
714-
);
715-
readonly attribute double inputUsage;
716-
readonly attribute unrestricted double inputQuota;
717-
attribute EventHandler onquotaoverflow;
718-
719-
readonly attribute unsigned long topK;
720-
readonly attribute float temperature;
721-
722-
Promise<LanguageModel> clone(optional LanguageModelCloneOptions options = {});
723-
undefined destroy();
724-
};
725-
726-
[Exposed=Window, SecureContext]
727-
interface LanguageModelParams {
728-
readonly attribute unsigned long defaultTopK;
729-
readonly attribute unsigned long maxTopK;
730-
readonly attribute float defaultTemperature;
731-
readonly attribute float maxTemperature;
732-
};
733-
734-
dictionary LanguageModelCreateCoreOptions {
735-
// Note: these two have custom out-of-range handling behavior, not in the IDL layer.
736-
// They are unrestricted double so as to allow +Infinity without failing.
737-
unrestricted double topK;
738-
unrestricted double temperature;
739-
740-
sequence<LanguageModelExpected> expectedInputs;
741-
sequence<LanguageModelExpected> expectedOutputs;
742-
};
743-
744-
dictionary LanguageModelCreateOptions : LanguageModelCreateCoreOptions {
745-
AbortSignal signal;
746-
AICreateMonitorCallback monitor;
747-
748-
sequence<LanguageModelMessage> initialPrompts;
749-
};
750-
751-
dictionary LanguageModelPromptOptions {
752-
object responseConstraint;
753-
AbortSignal signal;
754-
};
755-
756-
dictionary LanguageModelAppendOptions {
757-
AbortSignal signal;
758-
};
759-
760-
dictionary LanguageModelCloneOptions {
761-
AbortSignal signal;
762-
};
763-
764-
dictionary LanguageModelExpected {
765-
required LanguageModelMessageType type;
766-
sequence<DOMString> languages;
767-
};
768-
769-
// The argument to the prompt() method and others like it
770-
771-
typedef (
772-
sequence<LanguageModelMessage>
773-
// Shorthand for `[{ role: "user", content: [{ type: "text", value: providedValue }] }]`
774-
or DOMString
775-
) LanguageModelPrompt;
776-
777-
dictionary LanguageModelMessage {
778-
required LanguageModelMessageRole role;
779-
780-
// The DOMString branch is shorthand for `[{ type: "text", value: providedValue }]`
781-
required (DOMString or sequence<LanguageModelMessageContent>) content;
782-
};
783-
784-
dictionary LanguageModelMessageContent {
785-
required LanguageModelMessageType type;
786-
required LanguageModelMessageValue value;
787-
};
788-
789-
enum LanguageModelMessageRole { "system", "user", "assistant" };
790-
791-
enum LanguageModelMessageType { "text", "image", "audio" };
792-
793-
typedef (
794-
ImageBitmapSource
795-
or AudioBuffer
796-
or BufferSource
797-
or DOMString
798-
) LanguageModelMessageValue;
799-
```
800-
801688
### Instruction-tuned versus base models
802689

803690
We intend for this API to expose instruction-tuned models. Although we cannot mandate any particular level of quality or instruction-following capability, we think setting this base expectation can help ensure that what browsers ship is aligned with what web developers expect.

index.bs

Lines changed: 155 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,155 @@
1+
<pre class='metadata'>
2+
Title: Prompt API
3+
Shortname: prompt
4+
Level: None
5+
Status: CG-DRAFT
6+
Group: webml
7+
Repository: webmachinelearning/prompt-api
8+
URL: https://webmachinelearning.github.io/prompt-api
9+
Editor: Domenic Denicola, Google https://google.com, [email protected], https://domenic.me/
10+
Abstract: The prompt API gives web pages the ability to directly prompt a language model
11+
Markup Shorthands: markdown yes, css no
12+
Complain About: accidental-2119 yes, missing-example-ids yes
13+
Assume Explicit For: yes
14+
Default Biblio Status: current
15+
Boilerplate: omit conformance
16+
Indent: 2
17+
Die On: warning
18+
</pre>
19+
20+
<h2 id="intro">Introduction</h2>
21+
22+
TODO
23+
24+
<h2 id="dependencies">Dependencies</h2>
25+
26+
This specification depends on the Infra Standard. [[!INFRA]]
27+
28+
As with the rest of the web platform, human languages are identified in these APIs by BCP 47 language tags, such as "`ja`", "`en-US`", "`sr-Cyrl`", or "`de-CH-1901-x-phonebk-extended`". The specific algorithms used for validation, canonicalization, and language tag matching are those from the <cite>ECMAScript Internationalization API Specification</cite>, which in turn defers some of its processing to <cite>Unicode Locale Data Markup Language (LDML)</cite>. [[BCP47]] [[!ECMA-402]] [[UTS35]].
29+
30+
These APIs are part of a family of APIs expected to be powered by machine learning models, which share common API surface idioms and specification patterns. Currently, the specification text for these shared parts lives in [[WRITING-ASSISTANCE-APIS#supporting]], and the common privacy and security considerations are discussed in [[WRITING-ASSISTANCE-APIS#privacy]] and [[WRITING-ASSISTANCE-APIS#security]]. Implementing these APIs requires implementing that shared infrastructure, and conforming to those privacy and security considerations. But it does not require implementing or exposing the actual writing assistance APIs. [[!WRITING-ASSISTANCE-APIS]]
31+
32+
<h2 id="api">The API</h2>
33+
34+
<xmp class="idl">
35+
[Exposed=Window, SecureContext]
36+
interface LanguageModel : EventTarget {
37+
static Promise<LanguageModel> create(optional LanguageModelCreateOptions options = {});
38+
static Promise<Availability> availability(optional LanguageModelCreateCoreOptions options = {});
39+
static Promise<LanguageModelParams?> params();
40+
41+
// These will throw "NotSupportedError" DOMExceptions if role = "system"
42+
Promise<DOMString> prompt(
43+
LanguageModelPrompt input,
44+
optional LanguageModelPromptOptions options = {}
45+
);
46+
ReadableStream promptStreaming(
47+
LanguageModelPrompt input,
48+
optional LanguageModelPromptOptions options = {}
49+
);
50+
Promise<undefined> append(
51+
LanguageModelPrompt input,
52+
optional LanguageModelAppendOptions options = {}
53+
);
54+
55+
Promise<double> measureInputUsage(
56+
LanguageModelPrompt input,
57+
optional LanguageModelPromptOptions options = {}
58+
);
59+
readonly attribute double inputUsage;
60+
readonly attribute unrestricted double inputQuota;
61+
attribute EventHandler onquotaoverflow;
62+
63+
readonly attribute unsigned long topK;
64+
readonly attribute float temperature;
65+
66+
Promise<LanguageModel> clone(optional LanguageModelCloneOptions options = {});
67+
undefined destroy();
68+
};
69+
70+
[Exposed=Window, SecureContext]
71+
interface LanguageModelParams {
72+
readonly attribute unsigned long defaultTopK;
73+
readonly attribute unsigned long maxTopK;
74+
readonly attribute float defaultTemperature;
75+
readonly attribute float maxTemperature;
76+
};
77+
78+
dictionary LanguageModelCreateCoreOptions {
79+
// Note: these two have custom out-of-range handling behavior, not in the IDL layer.
80+
// They are unrestricted double so as to allow +Infinity without failing.
81+
unrestricted double topK;
82+
unrestricted double temperature;
83+
84+
sequence<LanguageModelExpected> expectedInputs;
85+
sequence<LanguageModelExpected> expectedOutputs;
86+
};
87+
88+
dictionary LanguageModelCreateOptions : LanguageModelCreateCoreOptions {
89+
AbortSignal signal;
90+
CreateMonitorCallback monitor;
91+
92+
sequence<LanguageModelMessage> initialPrompts;
93+
};
94+
95+
dictionary LanguageModelPromptOptions {
96+
object responseConstraint;
97+
AbortSignal signal;
98+
};
99+
100+
dictionary LanguageModelAppendOptions {
101+
AbortSignal signal;
102+
};
103+
104+
dictionary LanguageModelCloneOptions {
105+
AbortSignal signal;
106+
};
107+
108+
dictionary LanguageModelExpected {
109+
required LanguageModelMessageType type;
110+
sequence<DOMString> languages;
111+
};
112+
113+
// The argument to the prompt() method and others like it
114+
115+
typedef (
116+
sequence<LanguageModelMessage>
117+
// Shorthand for `[{ role: "user", content: [{ type: "text", value: providedValue }] }]`
118+
or DOMString
119+
) LanguageModelPrompt;
120+
121+
dictionary LanguageModelMessage {
122+
required LanguageModelMessageRole role;
123+
124+
// The DOMString branch is shorthand for `[{ type: "text", value: providedValue }]`
125+
required (DOMString or sequence<LanguageModelMessageContent>) content;
126+
};
127+
128+
dictionary LanguageModelMessageContent {
129+
required LanguageModelMessageType type;
130+
required LanguageModelMessageValue value;
131+
};
132+
133+
enum LanguageModelMessageRole { "system", "user", "assistant" };
134+
135+
enum LanguageModelMessageType { "text", "image", "audio" };
136+
137+
typedef (
138+
ImageBitmapSource
139+
or AudioBuffer
140+
or BufferSource
141+
or DOMString
142+
) LanguageModelMessageValue;
143+
</xmp>
144+
145+
<h3 id="permissions-policy">Permissions policy integration</h3>
146+
147+
Access to the prompt API is gated behind the [=policy-controlled feature=] "<dfn permission>language-model</dfn>", which has a [=policy-controlled feature/default allowlist=] of <code>[=default allowlist/'self'=]</code>.
148+
149+
<h2 id="privacy">Privacy considerations</h2>
150+
151+
Please see [[WRITING-ASSISTANCE-APIS#privacy]] for a discussion of privacy considerations for the prompt API. That text was written to apply to all APIs sharing the same infrastructure, as noted in [[#dependencies]].
152+
153+
<h2 id="security">Security considerations</h2>
154+
155+
Please see [[WRITING-ASSISTANCE-APIS#security]] for a discussion of security considerations for the prompt API. That text was written to apply to all APIs sharing the same infrastructure, as noted in [[#dependencies]].

0 commit comments

Comments
 (0)