add Alan AI reference

This commit is contained in:
Olga Kolyachko committed 2023-03-06 12:35:06 +04:00
1 parent 14374e5306
commit 7f8e84b390
2 files changed
+527

No files matched your search

+498
View File
@@ -0,0 +1,498 @@
---
title: Alan AI
date: 2023-03-03 6:00:00
background: bg-[#4aa181]
tags:
- AI
- AlanAI
- Prompts
- Tips
categories:
- Toolkit
intro: This cheat covers all major script concepts, client API methods, handlers and other tools to create a multimodal conversational experience with Alan AI
---
Dialog script
-------------
### Intents & patterns
Define a voice command to play a response
``` {.wrap}
intent('pattern'[, 'patternN'], reply('pattern'))
```
Define a voice command to play a response or perform an action
``` {.wrap}
intent('pattern'[, 'patternN'], p => { action })
```
Define alternatives
``` {.wrap}
intent('phrase1|phrase2')
```
Define optional words and phrases
``` {.wrap}
intent('pattern (optional phrase|)')
```
### Response functions
Play a response (in case of multiple patterns, a response is picked at random)
``` {.wrap}
reply('pattern'[, 'patternN'])
```
Play a response
``` {.wrap}
p.play('pattern')
```
Define voice settings for the assistant reply: ``accent (en, fr, de, it, ru, es)``, ``gender (male/female)``, ``voice type``, ``speaking pitch``, ``speaking rate``
``` {.wrap}
p.play([voice(code, gender, type, pitch, rate), ]'pattern')
```
Define play options: ``force:true`` (execute if the button is inactive), ``activate:true`` (activate the button before), ``deactivate:true`` (deactivate the button after)
``` {.wrap}
p.play('pattern'[, opts(options)])
```
Send a command to the app
``` {.wrap}
p.play({command:data})
```
### User-defined slots
Define a static list of values expected in the input
``` {.wrap}
$(SLOTNAME value1|value2) => p.SLOTNAME.value
```
Provide labels to classify or identify the slot values
``` {.wrap}
$(SLOTNAME value1~label1|value2~label2) => p.SLOTNAME.label
```
Enable fuzzy matching to capture similar variants
``` {.wrap}
$(SLOTNAME~ value1|value2) => p.SLOTNAME.value
```
Make a slot optional
``` {.wrap}
$(SLOTNAME value1|value2|)
```
Capture several slot values
``` {.wrap}
intent('$(SLOTNAME value1|value2) and $(SLOTNAME value1|value2 )') => p.SLOTNAME_ (array), p.SLOTNAME_[0].value, p.SLOTNAME_[1].value
```
### Predefined slots
Capture date values
``` {.wrap}
$(DATE) => p.DATE.value, p.DATE.moment, p.DATE.luxon
```
Capture time values
``` {.wrap}
$(TIME) => p.TIME.value, p.TIME.moment
```
Capture cardinal numbers
``` {.wrap}
$(NUMBER) => p.NUMBER.value, p.NUMBER.number
```
Capture ordinal numbers
``` {.wrap}
$(ORDINAL) => p.ORDINAL.value, p.ORDINAL.number
```
Capture locations
``` {.wrap}
$(LOC) => p.LOC.value
```
Capture names
``` {.wrap}
$(NAME) => p.NAME.value
```
### Dynamic slots
Define a dynamic slot at the project level
``` {.wrap}
project.name = {en: "value1|value2|value3"}
$(SLOTNAME p:name) => p.SLOTNAME.value
```
Define a dynamic slot at the dialog session level
``` {.wrap}
p.userData.name = {en: "value1|value2|value3"}
$(SLOTNAME u:name) => p.SLOTNAME.value
```
Get data for a dynamic slot with the visual state
``` {.wrap}
let name = ["value1|value2|value3"]
p.visual.data = {en: name};
$(SLOTNAME v:name) => p.SLOTNAME.value
```
Define a dynamic slot in a short form
``` {.wrap}
project.name = {en: "value1|value2|value3"}
$(p:name) => p.SLOTNAME.value
```
Define labels for dynamic slots: see [User-defined slots](#user-defined-slots).
Enable fuzzy matching for dynamic slots: see [User-defined slots](#user-defined-slots).
Make a dynamic slot optional: see [User-defined slots](#user-defined-slots).
Capture several slot values: see [User-defined slots](#user-defined-slots).
### RegEx slots
Capture digit and/or letter combination
``` {.wrap}
const reg = "([A-Za-z]{1}\\s?){6}"
$(SLOTNAME* ${reg}) => p.SLOTNAME.value
```
Capture any user’s input
``` {.wrap}
$(SLOTNAME* .+) => p.SLOTNAME.value
```
### Contexts
Define a context
``` {.wrap}
let contextName = context(() => { action })
```
Activate a context
``` {.wrap}
intent('pattern', p => {..., p.then(contextName)}
```
Pass data to the context
``` {.wrap}
p.then(contextName, state: {data:yourData}) => p.state.data
```
Resolve a context
``` {.wrap}
p.resolve([data:yourData])
```
Reset a context
``` {.wrap}
p.resetContext()
```
Define intents to be matched at any time without switching the current context
``` {.wrap}
intent(noctx, 'pattern', ...) or noContext(() => {intent(...)})
```
Play a prompt for an expected input
``` {.wrap}
fallback('pattern1'[, 'patternN'])
```
Title a context
``` {.wrap}
title('contextName')
```
### Predefined objects
Store static device- and user-specific data passed from the client app
``` {.wrap}
authData.data => p.authData.data
```
Store state data to be available globally at the project scope
``` {.wrap}
project.info = {data:yourData} => project.info.data
```
Store the intent match score
``` {.wrap}
p.score
```
Store data to be passed between contexts
``` {.wrap}
p.state.data
```
Store visual context data to be passed from the client app with ``setVisualState()``
``` {.wrap}
p.visual.data
```
Store user-specific state data to be accessible during the dialog session
``` {.wrap}
p.userData.data
```
### Predefined callbacks
Define actions to be performed when the script is saved and dialog model is built
``` {.wrap}
onCreateProject(() => { action })
```
Define actions to be performed when the dialog session starts
``` {.wrap}
onCreateUser((p) => { action })
```
Define actions to be performed when the dialog session ends
``` {.wrap}
onCleanupUser((p) => { action })
```
Define actions to be performed when the visual state is set
``` {.wrap}
onVisualState((p, s) => { action })
```
Define actions to be performed when a user event is triggered in the client app: ``buttonReady``, ``buttonClicked``, ``micPermissionPrompt``, ``micAllowed``, ``firstActivate``, ``showPopup``, ``popupCloseClicked``, ``recognized``
``` {.wrap}
onUserEvent((p, e) => { action })
```
Define actions to be performed when a context is activated
``` {.wrap}
onEnter((p) => { action })
```
### Q&A service
Define a URL of a resource to be indexed
``` {.wrap}
corpus({url: url, depth: depthLevel})
```
Define text corpus to be used by the assistant in the dialog
``` {.wrap}
corpus('text')
```
### Built-in JS libraries
Make API calls
``` {.wrap}
axios, request
```
Work with time
``` {.wrap}
moment-timezone, luxon
```
Work with arrays, numbers, objects, strings and so on
``` {.wrap}
lodash
```
### Other
Provide a list of hints to help recognize specific terms
``` {.wrap}
recognitionHints('hint'[, 'hintN'])
```
Write info messages to Alan Studio logs
``` {.wrap}
console.log(data)
```
Write error messages to Alan Studio logs
``` {.wrap}
console.error(data)
```
Client SDK
----------
### Client API methods
Send information about the visual state from the client app to the dialog script
``` {.wrap}
setVisualState(visualStateData:object)
```
Send data or perform actions without a voice command
``` {.wrap}
projectAPI.method = function(p, param, callback) {
p.userData.data = param.data;
callback();
};
callProjectApi(method:string, data:object, callback:function)
```
Play a text message in the client app
``` {.wrap}
playText(text:string)
```
Send a text message to Alan as the user’s input
``` {.wrap}
sendText(text:string)
```
Execute a command in the client app
``` {.wrap}
playCommand(command:object)
```
### Client API methods (continued)
Activate the Alan button programmatically
``` {.wrap}
activate()
```
Deactivate the Alan button programmatically
``` {.wrap}
deactivate()
```
Check the Alan button state
``` {.wrap}
isActive()
```
Remove the Alan button from the parent element, page (supported on Web, Ionic)
``` {.wrap}
remove()
```
Check the state of the wake word (supported on iOS, Android)
``` {.wrap}
getWakewordEnabled()
```
Set the state of the wake word (supported on iOS, Android)
``` {.wrap}
setWakewordEnabled(enabled:boolean)
```
### Handlers
// Examples are provided for the Web platform
Handle commands sent from the dialog script to the client app
``` {.wrap}
onCommand: function (commandData) { action }
```
Handle Alan button state changes
``` {.wrap}
onButtonState: function (e) { action }
```
Handle connection status to the virtual assistant project in the Alan Cloud
``` {.wrap}
onConnectionStatus: function (e) { action }
```
Handle events received from Alan
``` {.wrap}
onEvent: function (e) { action }
```
Also see
--------
- [Alan AI website](https://alan.app)
- [About the Alan Platform](https://alan.app/platform)
- [Alan AI documentation](https://alan.app/docs)
<style>
em { font-size: 0.785em; }
strong {font-weight: 400;}
ul.collapsible > li > pre { padding-left: 0; padding-right: 0; font-size: 0.925em;}
</style>
+29
View File
@@ -0,0 +1,29 @@
<svg width="30" height="30" viewBox="0 0 30 30" fill="none" xmlns="http://www.w3.org/2000/svg">
<path fill-rule="evenodd" clip-rule="evenodd" d="M10.886 5.0037C10.8493 5.00124 10.8123 5 10.7752 5H10.1365H18.9042H19.7588H19.1202C19.0831 5 19.0461 5.00124 19.0094 5.0037C19.5204 5.03978 19.9792 5.33707 20.2158 5.79282L29.9637 24.5724C29.9876 24.6183 30 24.6692 30 24.7208C30 24.9001 29.8533 25.0454 29.6723 25.0454H22.9802C22.489 25.0454 22.039 24.7734 21.8144 24.3407L14.9477 11.1119L11.4222 17.9037H14.1684C14.6607 17.9037 15.1114 18.1769 15.3355 18.611L18.1695 24.1006C18.2167 24.1921 18.2413 24.2934 18.2413 24.3962C18.2413 24.7547 17.9479 25.0454 17.5859 25.0454H0.491577C0.220087 25.0454 0 24.8274 0 24.5585C0 24.481 0.0186505 24.4047 0.054403 24.3358L9.67959 5.79282C9.91616 5.33707 10.375 5.03978 10.886 5.0037Z" fill="url(#paint0_linear_5_21)"/>
<path fill-rule="evenodd" clip-rule="evenodd" d="M11.4222 17.9037H14.1684C14.6607 17.9037 15.1114 18.1769 15.3355 18.611L18.1695 24.1006C18.2167 24.1921 18.2413 24.2934 18.2413 24.3962C18.2413 24.7547 17.9479 25.0454 17.5859 25.0454H6.91518C7.40638 25.0454 7.85636 24.7734 8.08097 24.3407L11.4222 17.9037Z" fill="url(#paint1_linear_5_21)"/>
<path fill-rule="evenodd" clip-rule="evenodd" d="M11.4222 17.9037L8.08098 24.3407C7.85637 24.7734 7.40639 25.0454 6.91518 25.0454H0.535C0.457182 25.0454 0.380475 25.0271 0.31119 24.992C0.0694704 24.8696 -0.0262793 24.5762 0.0973275 24.3368L3.00755 18.6994C3.25969 18.211 3.76679 17.9037 4.32057 17.9037H11.4222Z" fill="url(#paint2_linear_5_21)"/>
<path fill-rule="evenodd" clip-rule="evenodd" d="M11.4222 17.9037H4.32057C3.76679 17.9037 3.25968 18.211 3.00755 18.6994L9.67959 5.79282C9.93228 5.30602 10.4385 5 10.9911 5H19.7588H19.1202C18.5062 5 17.9437 5.34002 17.663 5.88092L11.4222 17.9037Z" fill="url(#paint3_linear_5_21)"/>
<path fill-rule="evenodd" clip-rule="evenodd" d="M12.2324 5.88092C11.9516 5.34002 11.3892 5 10.7752 5H10.1366H18.9042C19.4569 5 19.9631 5.30602 20.2158 5.79282L29.9637 24.5724C29.9876 24.6183 30 24.6692 30 24.7208C30 24.9001 29.8533 25.0454 29.6723 25.0454H22.9802C22.489 25.0454 22.039 24.7734 21.8144 24.3407L12.2324 5.88092Z" fill="url(#paint4_linear_5_21)"/>
<defs>
<linearGradient id="paint0_linear_5_21" x1="24.0259" y1="19.4975" x2="13.9048" y2="6.39957" gradientUnits="userSpaceOnUse">
<stop stop-color="#606980"/>
<stop offset="1" stop-color="#7C88A6"/>
</linearGradient>
<linearGradient id="paint1_linear_5_21" x1="10.1351" y1="22.8943" x2="11.5358" y2="19.4456" gradientUnits="userSpaceOnUse">
<stop stop-color="#606980"/>
<stop offset="1" stop-color="#7C88A6"/>
</linearGradient>
<linearGradient id="paint2_linear_5_21" x1="3.38846" y1="22.8812" x2="5.34797" y2="19.1372" gradientUnits="userSpaceOnUse">
<stop stop-color="#8B96AF"/>
<stop offset="1" stop-color="#9BA5C0"/>
</linearGradient>
<linearGradient id="paint3_linear_5_21" x1="14.4868" y1="7.26847" x2="9.2853" y2="17.3803" gradientUnits="userSpaceOnUse">
<stop stop-color="#2E364D"/>
<stop offset="1" stop-color="#3D4766"/>
</linearGradient>
<linearGradient id="paint4_linear_5_21" x1="25.9364" y1="25.0454" x2="15.719" y2="5.07516" gradientUnits="userSpaceOnUse">
<stop stop-color="#606980"/>
<stop offset="1" stop-color="#7C88A6"/>
</linearGradient>
</defs>
</svg>

After

Width:  |  Height:  |  Size: 3.2 KiB