WPT details: Web platform tests cover the API surface adequately: https://wpt.fyi/results/ai/language-model These attempt to mitigate execution environments differences, e.g. stub/full implementations (content_shell, chrome), and device/model states (unavailable, downloadable, downloaded). The core responses of real models can be unpredictable (especially without sampling parameters) and may cause inconsistent test results, but some facets are more readily testable, e.g. the adherence to structured output response constraints. Test coverage and reliability improvements are ongoing, including planning for WebDriver extensions.
Prompt API gives web developers direct access to a browser-provided on-device AI language model. The API design offers fine-grained control, aligned with cloud API shapes, for progressively enhancing sites with model interactions tailored to individualized use cases. This complements task-based language model APIs, for example, Summarizer API, as well as a variety of APIs and frameworks for generalized on-device inference with developer-supplied ML models. The initial implementation supports text, image, and audio inputs. In addition, response constraints ensure that generated text conforms with predefined regex and JSON schema formats. This supports a variety of use cases, from generating image captions and performing visual searches to transcribing audio, classifying sound events, generating text following specific instructions, and extracting information or insights from multi-modal source material. This API has been shipped in [Chrome Extensions](https://chromewebstore.google.com/category/extensions). An enterprise policy [GenAILocalFoundationalModelSettings](https://chromeenterprise.google/policies/#GenAILocalFoundationalModelSettings) is available to disable the underlying model downloading, which would render this API unavailable. Enterprise admins can also set the [BuiltInAIAPIsEnabled](https://chromeenterprise.google/policies/#BuiltInAIAPIsEnabled) policy to block Built-In AI API usage, while still permitting other on-device GenAI features. Language support log: - Chrome M139 and earlier only supported English ('en') - Chrome M140 added support for Spanish and Japanese ('es' and 'ja')
Direct access to a language model can help web developers accomplish tasks beyond those with dedicated APIs (e.g. Summarizer API) , and tailor their usage for site-specific requirements. Compared to the low-level APIs approach (e.g a custom AI model run via WebGPU, WASM, or WebNN), using the built-in language model can save the user's bandwidth and disk space, and has a lower barrier to entry. The design offers simple shorthands for common patterns (e.g. await session.prompt(‘write a haiku’)), and supports more complex use cases for handling structured content sequences, streaming responses, availability checks, session management, and response constraints.
Samples: https://chrome.dev/web-ai-demos/prompt-api-playground https://chrome.dev/web-ai-demos/prompt-api-weather https://ai.etiennenoel.com/prompt-api https://ai.etiennenoel.com/multimodal-prompt-api https://www.clarkduvall.com/ai
Explainers: https://github.com/webmachinelearning/prompt-api/blob/main/README.md