diff --git a/source/_posts/alan-ai.md b/source/_posts/alan-ai.md index b8740a9..d0ae0f4 100644 --- a/source/_posts/alan-ai.md +++ b/source/_posts/alan-ai.md @@ -3,76 +3,85 @@ title: Alan AI date: 2023-03-03 6:00:00 background: bg-[#4aa181] tags: - - AI - - AlanAI - - Prompts - - Tips + - AI + - AlanAI + - Prompts + - Tips categories: - - Toolkit -intro: This cheat sheet covers all major script concepts, client API methods, handlers and other tools to create a multimodal conversational experience with Alan AI + - Toolkit +intro: + This cheat sheet covers all major script concepts, client API methods, handlers and other tools to create a multimodal + conversational experience with Alan AI --- -### Legend +### Legend -- ``pattern`` — phrase to invoke a voice/text command or a response to be played -- ``value`` — specified value -- ``params`` — passed parameters -- ``action`` — action to be performed -- ``output`` — data outcome -- ``[...]`` — optional data or parameters +- `pattern` — phrase to invoke a voice/text command or a response to be played +- `value` — specified value +- `params` — passed parameters +- `action` — action to be performed +- `output` — data outcome +- `[...]` — optional data or parameters -Dialog script -------------- +## Dialog script ### Intents & patterns Define a voice/text command to play a response -``` {.wrap} +```{.wrap} intent('pattern'[, 'patternN'], reply('pattern')) ``` Define a voice/text command to play a response or perform an action -``` {.wrap} + +```{.wrap} intent('pattern'[, 'patternN'], p => { action }) ``` Define alternatives -``` {.wrap} + +```{.wrap} intent('phrase1|phrase2') ``` Define optional words and phrases -``` {.wrap} + +```{.wrap} intent('pattern (optional phrase|)') ``` - - ### Response functions Play a response (in case of multiple patterns, a response is picked at random) -``` {.wrap} + +```{.wrap} reply('pattern'[, 'patternN']) ``` Play a response -``` {.wrap} + +```{.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} +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} +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} + +```{.wrap} p.play({command:data}) ``` @@ -80,31 +89,31 @@ p.play({command:data}) Define a static list of values expected in the input -``` {.wrap} +```{.wrap} $(SLOTNAME value1|value2) => p.SLOTNAME.value ``` Provide labels to classify or identify the slot values -``` {.wrap} +```{.wrap} $(SLOTNAME value1~label1|value2~label2) => p.SLOTNAME.label ``` Enable fuzzy matching to capture similar variants -``` {.wrap} +```{.wrap} $(SLOTNAME~ value1|value2) => p.SLOTNAME.value ``` Make a slot optional -``` {.wrap} +```{.wrap} $(SLOTNAME value1|value2|) ``` Capture several slot values -``` {.wrap} +```{.wrap} intent('$(SLOTNAME value1|value2) and $(SLOTNAME value1|value2 )') => p.SLOTNAME_ (array), p.SLOTNAME_[0].value, p.SLOTNAME_[1].value ``` @@ -112,37 +121,37 @@ intent('$(SLOTNAME value1|value2) and $(SLOTNAME value1|value2 )') => p.SLOTNAME Capture date values -``` {.wrap} +```{.wrap} $(DATE) => p.DATE.value, p.DATE.moment, p.DATE.luxon ``` Capture time values -``` {.wrap} +```{.wrap} $(TIME) => p.TIME.value, p.TIME.moment ``` Capture cardinal numbers -``` {.wrap} +```{.wrap} $(NUMBER) => p.NUMBER.value, p.NUMBER.number ``` Capture ordinal numbers -``` {.wrap} +```{.wrap} $(ORDINAL) => p.ORDINAL.value, p.ORDINAL.number ``` Capture locations -``` {.wrap} +```{.wrap} $(LOC) => p.LOC.value ``` Capture names -``` {.wrap} +```{.wrap} $(NAME) => p.NAME.value ``` @@ -150,21 +159,21 @@ $(NAME) => p.NAME.value Define a dynamic slot at the project level -``` {.wrap} +```{.wrap} project.name = {en: "value1|value2|value3"} $(SLOTNAME p:name) => p.SLOTNAME.value ``` Define a dynamic slot at the dialog session level -``` {.wrap} +```{.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} +```{.wrap} let name = ["value1|value2|value3"] p.visual.data = {en: name}; $(SLOTNAME v:name) => p.SLOTNAME.value @@ -172,7 +181,7 @@ $(SLOTNAME v:name) => p.SLOTNAME.value Define a dynamic slot in a short form -``` {.wrap} +```{.wrap} project.name = {en: "value1|value2|value3"} $(p:name) => p.SLOTNAME.value ``` @@ -185,19 +194,18 @@ 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} +```{.wrap} const reg = "([A-Za-z]{1}\\s?){6}" $(SLOTNAME* ${reg}) => p.SLOTNAME.value ``` Capture any user’s input -``` {.wrap} +```{.wrap} $(SLOTNAME* .+) => p.SLOTNAME.value ``` @@ -205,50 +213,49 @@ $(SLOTNAME* .+) => p.SLOTNAME.value Define a context -``` {.wrap} +```{.wrap} let contextName = context(() => { action }) ``` Activate a context -``` {.wrap} +```{.wrap} intent('pattern', p => {..., p.then(contextName)} ``` Pass data to the context -``` {.wrap} +```{.wrap} p.then(contextName, state: {data:yourData}) => p.state.data ``` Resolve a context -``` {.wrap} +```{.wrap} p.resolve([data:yourData]) ``` - Reset a context -``` {.wrap} +```{.wrap} p.resetContext() ``` Define intents to be matched at any time without switching the current context -``` {.wrap} +```{.wrap} intent(noctx, 'pattern', ...) or noContext(() => {intent(...)}) ``` Play a prompt for an expected input -``` {.wrap} +```{.wrap} fallback('pattern1'[, 'patternN']) ``` Title a context -``` {.wrap} +```{.wrap} title('contextName') ``` @@ -256,37 +263,37 @@ title('contextName') Store static device- and user-specific data passed from the client app -``` {.wrap} +```{.wrap} authData.data => p.authData.data ``` Store state data to be available globally at the project scope -``` {.wrap} +```{.wrap} project.info = {data:yourData} => project.info.data ``` Store the intent match score -``` {.wrap} +```{.wrap} p.score ``` Store data to be passed between contexts -``` {.wrap} +```{.wrap} p.state.data ``` -Store visual context data to be passed from the client app with ``setVisualState()`` +Store visual context data to be passed from the client app with `setVisualState()` -``` {.wrap} +```{.wrap} p.visual.data ``` Store user-specific state data to be accessible during the dialog session -``` {.wrap} +```{.wrap} p.userData.data ``` @@ -294,51 +301,52 @@ p.userData.data Define actions to be performed when the script is saved and dialog model is built -``` {.wrap} +```{.wrap} onCreateProject(() => { action }) ``` Define actions to be performed when the dialog session starts -``` {.wrap} +```{.wrap} onCreateUser((p) => { action }) ``` Define actions to be performed when the dialog session ends -``` {.wrap} +```{.wrap} onCleanupUser((p) => { action }) ``` Define actions to be performed when the visual state is set -``` {.wrap} +```{.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`` +Define actions to be performed when a user event is triggered in the client app: `buttonReady`, `buttonClicked`, +`micPermissionPrompt`, `micAllowed`, `firstActivate`, `showPopup`, `popupCloseClicked`, `recognized` -``` {.wrap} +```{.wrap} onUserEvent((p, e) => { action }) ``` Define actions to be performed when a context is activated -``` {.wrap} +```{.wrap} onEnter((p) => { action }) ``` - ### Q&A service Define a URL of a resource to be indexed -``` {.wrap} +```{.wrap} corpus({url: url, depth: depthLevel}) ``` Define text corpus to be used by the assistant in the dialog -``` {.wrap} + +```{.wrap} corpus('text') ``` @@ -346,19 +354,19 @@ corpus('text') Make API calls -``` {.wrap} +```{.wrap} axios, request ``` Work with time -``` {.wrap} +```{.wrap} moment-timezone, luxon ``` Work with arrays, numbers, objects, strings and so on -``` {.wrap} +```{.wrap} lodash ``` @@ -366,36 +374,35 @@ lodash Provide a list of hints to help recognize specific terms -``` {.wrap} +```{.wrap} recognitionHints('hint'[, 'hintN']) ``` Write info messages to Alan Studio logs -``` {.wrap} +```{.wrap} console.log(data) ``` Write error messages to Alan Studio logs -``` {.wrap} +```{.wrap} console.error(data) ``` -Client SDK ----------- +## Client SDK ### Client API methods Send information about the visual state from the client app to the dialog script -``` {.wrap} +```{.wrap} setVisualState(visualStateData:object) ``` Send data or perform actions without a voice/text command -``` {.wrap} +```{.wrap} projectAPI.method = function(p, param, callback) { p.userData.data = param.data; callback(); @@ -406,19 +413,19 @@ callProjectApi(method:string, data:object, callback:function) Play a text message in the client app -``` {.wrap} +```{.wrap} playText(text:string) ``` Send a text message to Alan as the user’s input -``` {.wrap} +```{.wrap} sendText(text:string) ``` Execute a command in the client app -``` {.wrap} +```{.wrap} playCommand(command:object) ``` @@ -426,37 +433,37 @@ playCommand(command:object) Activate the Alan button programmatically -``` {.wrap} +```{.wrap} activate() ``` Deactivate the Alan button programmatically -``` {.wrap} +```{.wrap} deactivate() ``` Check the Alan button state -``` {.wrap} +```{.wrap} isActive() ``` Remove the Alan button from the parent element, page (supported on Web, Ionic) -``` {.wrap} +```{.wrap} remove() ``` Check the state of the wake word (supported on iOS, Android) -``` {.wrap} +```{.wrap} getWakewordEnabled() ``` Set the state of the wake word (supported on iOS, Android) -``` {.wrap} +```{.wrap} setWakewordEnabled(enabled:boolean) ``` @@ -466,42 +473,30 @@ setWakewordEnabled(enabled:boolean) Handle commands sent from the dialog script to the client app -``` {.wrap} +```{.wrap} onCommand: function (commandData) { action } ``` Handle Alan button state changes -``` {.wrap} +```{.wrap} onButtonState: function (e) { action } ``` Handle connection status to the virtual assistant project in the Alan Cloud -``` {.wrap} +```{.wrap} onConnectionStatus: function (e) { action } ``` Handle events received from Alan -``` {.wrap} +```{.wrap} onEvent: function (e) { action } ``` - - - -Also see --------- +## Also see - [Alan AI website](https://alan.app) - [About the Alan Platform](https://alan.app/platform) - [Alan AI documentation](https://alan.app/docs) - - - -