A special Chromium Prompt API provider for xsai, the extra-small AI SDK. Capable of performing tasks of text generations right in the Chromium-based browser (due to
AI on Chrome)
xsAI Chromium Prompt API Provider aligned the API of xsAI:
import { generateText } from '@xsai/generate-text'
import { checkPromptAvailability, createChatProvider } from 'xsai-chromium-prompt'
const availability = await checkPromptAvailability()
if (availability === 'available') {
const chatProvider = createChatProvider()
const { text } = await generateText({
...chatProvider.chat(),
messages: [{
content: 'Why is the sky blue?',
role: 'user'
}]
})
}xsai-chromium-prompt is just a wrapper for 🦖 Chromium Prompt API. It enables xsai to interface with Gemini Nano in Chrome. Text is the only avaliable sub-provider due to the limitation of AI on Chrome, whichs means that it can only create a provider for @xsai/generate-text and @xsai/stream-text.
xsai-chromium-prompt requires Chromium-based browsers that meets the hardware requirements to deploy Gemini Nano.
When using the Prompt API download monitor, the progress callback does not return 1.0 upon completion. Instead, it stops at a value slightly below 1.0 (e.g., 0.97), even though the download has finished successfully. Since that, the onProgress arguement will has the same problem that the last call of this function will return a value slightly below 1.0 (e.g., 0.97) too.
To solve this problem, you can utillize a lifecycle hook to run checkPromptAvailability that detects the availability. When the availability is available, set the progress to 1.
The code of the playground gives an example.
If the availability of the Prompt API is downloadable, the Gemini Nano model file will be downloaded after the generateText() or streamText() is called.
# npm
npm install xsai-chromium-prompt
# yarn
yarn add xsai-chromium-prompt
# pnpm
pnpm install xsai-chromium-prompt
# bun
bun install xsai-chromium-prompt
The Chromium Prompt API's LLM supports multimodal inputs, including image and audio. To enable these capabilities, developers must explicitly declare the expected input types when initializing the chat provider.
For example
const chatProvider = createChatProvider({
expectedInputs: [{ type: 'audio' }, { type: 'image' }]
})Examples (see above)
xsAI Chromium Prompt API is currently in an early stage of development and may introduce breaking changes at any time.