AI Shopping Assistant
<msc-ai-shopping-assistant /> is a is a web component based on Chrome Built-in AI Prompt API.
Users could use <msc-ai-shopping-assistant /> to connect with Gemini Nano to gather rich and amazing purchase experience.
The following demo is a LIVE shopping assistant. User could press the button to experience the flow.
Let's see what can <msc-ai-shopping-assistant /> do ?
Basic Usage
<msc-ai-shopping-assistant /> is a web component. All we need to do is put the required script into your HTML document. Then follow <msc-ai-shopping-assistant />'s html structure and everything will be all set.
Required Script
Structure
Put <msc-ai-shopping-assistant /> into HTML document. It will have different functions and looks with attribute mutation.
JavaScript Instantiation
<msc-ai-shopping-assistant /> could also use JavaScript to create DOM element. Here comes some examples.
Style Customization
Developers could apply styles to decorate <msc-ai-shopping-assistant />'s looking.
Otherwise, developers colud also modified <msc-ai-shopping-assistant />'s appearance by data-appearance.
- light: light mode.
- dark: dark mode.
- device: apply system setting.
Attributes
<msc-ai-shopping-assistant /> supports some attributes to let it become more convenience & useful.
aiconfig
Set aiconfig as <msc-built-in-ai-prompt />'s session create parameters.
placeholder
Set placeholder for user input field.
recommendproducts
Set recommendproducts for recommand products. AI will analysis user prompt for purchanse intent. Once true, <msc-ai-shopping-assistant /> will dispatch event with several keywords.
Properties
| Property Name | Type | Description |
|---|---|---|
aiconfig
|
Object | Getter / Setter aiconfig. (<msc-built-in-ai-prompt /> will take this for session create parameter) |
placeholder
|
String | Getter / Setter for user input field's placeholder. |
recommendproducts
|
Boolean | Getter / Setter for recommend products setting. |
open
|
Boolean | Getter for <msc-ai-shopping-assistant />'s open status. |
utterance
|
Object | Getter for <msc-ai-shopping-assistant />'s utterance. |
Mathods
| Mathod Signature | Description |
|---|---|
showModal()
|
Show <msc-ai-shopping-assistant />. |
close()
|
Close <msc-ai-shopping-assistant />. |
reset()
|
Reset all. (clear AI session & prompt context) |
productRecommend(data = {})
|
Pass products' information for <msc-ai-shopping-assistant />.※ data should be the following structure:
{
"content": "message you like to show",
"listings": [
{
"url": "pruduct link",
"title": "product title",
"description": "product description",
"thumbnail": "thumbnail url",
"price": "product price"
"action": "call to action content"
},
...
]
}
|
setVoiceAndRate({ voice, rate = 1 })
|
Setting Web Speech > SpeechSynthesisUtterance voice & rate. (voice should be SpeechSynthesisVoice) |
Event
| Event Signature | Description |
|---|---|
msc-ai-shopping-assistant-purchase-intent
|
Fired when AI analysis user's prompt has purchase intent. Developers could gather clues information from event.detail.※ event.detail:
{
"clues": {
"name": "emmashop 樂福鞋",
"category": "樂福鞋",
"requires": "",
"price": "<1000",
"quantity": 1,
"scenario": "",
"synonyms": [],
"size": 38.5,
"color": "",
"brand": "emmashop",
"used": false
}
}
|