Overhaul availability testing and add expected input languages for detector #31
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Add an
expectedInputLanguages
option to language detector creation API. This allows the browser to download relevant material if necessary, or fail-fast if a language the web developer needs to support is not available.Then, remove the
capabilities()
methods and the accompanyingAI*Capabilities
classes.For translator, the only useful capabilities API was
(await ai.translator.capabilities()).languagePairAvailable()
. We simplify this toawait ai.translator.availability()
. This design also avoids the complexity where we have to retrieve all the availability information for every combination of options during the call tocapabilities()
, for later sync access. Now we can just retrieve the relevant information during the call toavailability()
.Also, by unifying on using the same options for
create()
andavailability()
, we fix ShouldlanguagePairAvailable()
accept{sourceLanguage, targetLanguage}
instead of two parameters? #24.For language detector, the capabilities supplied both
(await ai.languageDetector.capabilities()).available
and(await ai.languageDetector.capabilities()).languageAvailable()
. We simplify this intoawait ai.languageDetector.availability()
, which can either take no arguments (emulatingavailable
) or take the same{ expectedInputLanguages }
argument ascreate()
(emulatinglanguageAvailable()
).See also webmachinelearning/writing-assistance-apis#22 and webmachinelearning/prompt-api#69.
Preview | Diff