Skip to content

Commit 24de050

Browse files
committed
Revamp capabilities API surface
* Rename from supportsInputLanguage() to languageAvailable(), to match the language detection API. Closes #7. (See also webmachinelearning/translation-api#19.) * Consolidate the various supportsXYZ() methods into a single createOptionsAvailable() method. This avoids the issue noted in webmachinelearning/translation-api#19, aligns us with the "available" suffix, and most importantly, lets a browser signal that it doesn't support certain combinations. (For example, Chrome right now doesn't support some combinations for the writer API.)
1 parent 0dd35db commit 24de050

File tree

1 file changed

+26
-26
lines changed

1 file changed

+26
-26
lines changed

README.md

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ Each of these capabilities objects has further methods which allow probing the s
157157

158158
```js
159159
const summarizerCapabilities = await ai.summarizer.capabilities();
160-
const supportsTeaser = summarizerCapabilities.supportsType("teaser");
160+
const supportsTeaser = summarizerCapabilities.createOptionsAvailable({ type: "teaser" });
161161

162162
if (supportsTeaser !== "no") {
163163
// We're good! Let's do the summarization using the built-in API.
@@ -174,7 +174,7 @@ if (supportsTeaser !== "no") {
174174
}
175175
```
176176
177-
In addition to methods to check if options (like `type` for summarizer, or `tone` for rewriter) are supported, all three APIs' capabilities objects have an additional method, `supportsInputLanguage(languageTag)`, which can be used to tell whether the model supports input and context in the given human language. It has the same three return values.
177+
In addition to methods to check if options (like `type` for summarizer, or `tone` for rewriter) are supported, all three APIs' capabilities objects have an additional method, `languageAvailable(languageTag)`, which can be used to tell whether the model supports input and context in the given human language. It has the same three return values.
178178
179179
### Download progress
180180
@@ -292,21 +292,21 @@ interface AISummarizer {
292292
interface AISummarizerCapabilities {
293293
readonly attribute AICapabilityAvailability available;
294294

295-
AICapabilityAvailability supportsType(AISummarizerType type);
296-
AICapabilityAvailability supportsFormat(AISummarizerFormat format);
297-
AICapabilityAvailability supportsLength(AISummarizerLength length);
295+
AICapabilityAvailability createOptionsAvailable(AISummarizerCreateCoreOptions options);
296+
AICapabilityAvailability languageAvailable(DOMString languageTag);
297+
};
298298

299-
AICapabilityAvailability supportsInputLanguage(DOMString languageTag);
299+
dictionary AISummarizerCreateCoreOptions {
300+
AISummarizerType type = "key-points";
301+
AISummarizerFormat format = "markdown";
302+
AISummarizerLength length = "short";
300303
};
301304

302-
dictionary AISummarizerCreateOptions {
305+
dictionary AISummarizerCreateOptions : AISummarizerCreateCoreOptions {
303306
AbortSignal signal;
304307
AICreateMonitorCallback monitor;
305308

306309
DOMString sharedContext;
307-
AISummarizerType type = "key-points";
308-
AISummarizerFormat format = "markdown";
309-
AISummarizerLength length = "short";
310310
};
311311

312312
dictionary AISummarizerSummarizeOptions {
@@ -345,21 +345,21 @@ interface AIWriter {
345345
interface AIWriterCapabilities {
346346
readonly attribute AICapabilityAvailability available;
347347

348-
AICapabilityAvailability supportsTone(AIWriterTone tone);
349-
AICapabilityAvailability supportsFormat(AIWriterFormat format);
350-
AICapabilityAvailability supportsLength(AIWriterLength length);
348+
AICapabilityAvailability createOptionsAvailable(AIWriterCreateCoreOptions options);
349+
AICapabilityAvailability languageAvailable(DOMString languageTag);
350+
};
351351

352-
AICapabilityAvailability supportsInputLanguage(DOMString languageTag);
352+
dictionary AIWriterCreateCoreOptions {
353+
AIWriterTone tone = "neutral",
354+
AIWriterFormat format = "markdown",
355+
AIWriterLength length = "short"
353356
};
354357

355-
dictionary AIWriterCreateOptions {
358+
dictionary AIWriterCreateOptions : AIWriterCreateCoreOptions {
356359
AbortSignal signal;
357360
AICreateMonitorCallback monitor;
358361

359362
DOMString sharedContext;
360-
AIWriterTone tone = "neutral",
361-
AIWriterFormat format = "markdown",
362-
AIWriterLength length = "short"
363363
};
364364

365365
dictionary AIWriterWriteOptions {
@@ -398,21 +398,21 @@ interface AIRewriter {
398398
interface AIRewriterCapabilities {
399399
readonly attribute AICapabilityAvailability available;
400400

401-
AICapabilityAvailability supportsTone(AIRewriterTone tone);
402-
AICapabilityAvailability supportsFormat(AIRewriterFormat format);
403-
AICapabilityAvailability supportsLength(AIRewriterLength length);
401+
AICapabilityAvailability createOptionsAvailable(AIRewriterCreateCoreOptions options);
402+
AICapabilityAvailability languageAvailable(DOMString languageTag);
403+
};
404404

405-
AICapabilityAvailability supportsInputLanguage(DOMString languageTag);
405+
dictionary AIRewriterCreateCoreOptions {
406+
AIRewriterTone tone = "as-is";
407+
AIRewriterFormat format = "as-is";
408+
AIRewriterLength length = "as-is";
406409
};
407410

408-
dictionary AIRewriterCreateOptions {
411+
dictionary AIRewriterCreateOptions : AIRewriterCreateCoreOptions {
409412
AbortSignal signal;
410413
AICreateMonitorCallback monitor;
411414

412415
DOMString sharedContext;
413-
AIRewriterTone tone = "as-is";
414-
AIRewriterFormat format = "as-is";
415-
AIRewriterLength length = "as-is";
416416
};
417417

418418
dictionary AIRewriterRewriteOptions {

0 commit comments

Comments
 (0)