Built-in AI Prompt
<msc-built-in-ai-prompt /> is a web component based on Chrome Built-in AI Prompt API.
Web developers could use <msc-built-in-ai-prompt /> to connect with Gemini Nano and provide vivid features.
<msc-built-in-ai-prompt /> is a non-UI component. But it will provide current status in data-status. That means web developers have maximum creation to build UI throuth this information.
The following demo is a product image analysis. User could pick a product image to let AI tell you what it is.
Let's see what can <msc-built-in-ai-prompt /> do ?
Basic Usage
<msc-built-in-ai-prompt /> is a web component. All we need to do is put the required script into your HTML document. Then follow <msc-built-in-ai-prompt />'s html structure and everything will be all set.
Required Script
Structure
Put <msc-built-in-ai-prompt /> into HTML document. It will have different functions and looks with attribute mutation.
There will be serverial status to indicate Built-in AI status. Check msc-built-in-ai-prompt[data-status] out.
- available:AI ready to use.
- downloadable:Need to download LLM first (browser supported).
- downloading:LLM downloading (browser supported).
- unsupported:current browser doesn't support Built-in AI.
- unavailable:current browser doesn't support Built-in AI.
Once <msc-built-in-ai-prompt /> in status: downloading, <msc-built-in-ai-prompt /> will show download progress in attribute data-progress.
Such as:
JavaScript Instantiation
<msc-built-in-ai-prompt /> could also use JavaScript to create DOM element. Here comes some examples.
Use <msc-built-in-ai-prompt />
<msc-built-in-ai-prompt /> provide same method as Chrome Built-in AI Prompt API. That means web developers need to create() session before prompt().
Non-streamed output
Streamed output
Multimodal capabilities
Property
| Property Name | Type | Description |
|---|---|---|
status
|
String | Getter current status. (available、downloadable、downloading、unsupported、unavailable) |
inputUsage
|
Number | Getter current session input usage information. |
inputQuota
|
Number | Getter current session input quota information. |
Mathods
| Mathod Signature | Description |
|---|---|
create(options = {})
|
Create session. |
prompt(content = '' [, options = {}])
|
Go prompt (non-streamed output). |
promptStreaming(content = '' [, options = {}])
|
Go prompt (streamed output). |
params()
|
The params() function informs you of the language model's parameters. |
measureInputUsage(content)
|
Measure how many token will be use for the content. |
destroy()
|
Destroy current session. |
※ The above methods are all async.
Events
| Event Signature | Description |
|---|---|
msc-built-in-ai-prompt-ready
|
Fired when LLM download done. |
msc-built-in-ai-prompt-download-progress
|
Fired when LLM downloading. Developers could gather result information through event.detail. |