Skip to content

Commit

Permalink
feat(server): restart a skill with the original utterance saved in co…
Browse files Browse the repository at this point in the history
…ntext
  • Loading branch information
louistiti committed May 8, 2022
1 parent 035c9d5 commit f4446ef
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 19 deletions.
25 changes: 20 additions & 5 deletions server/src/core/nlu.js
Original file line number Diff line number Diff line change
Expand Up @@ -172,9 +172,26 @@ class Nlu {
return resolve(null)
}

// Break the action loop
// Reprocess with the original utterance that triggered the context at first
if (processedData.core?.restart === true) {
const { originalUtterance } = this.conv.activeContext

this.conv.cleanActiveContext()
await this.process(originalUtterance, opts)
return resolve(null)
}

// In case there is no next action to prepare anymore
if (!processedData.action.next_action) {
this.conv.cleanActiveContext()
return resolve(null)
}

// Break the action loop and prepare for the next action if necessary
if (processedData.core?.isInActionLoop === false) {
this.conv.activeContext.isInActionLoop = false
this.conv.activeContext.isInActionLoop = !!processedData.action.loop
this.conv.activeContext.actionName = processedData.action.next_action
this.conv.activeContext.intent = `${processedData.classification.skill}.${processedData.action.next_action}`
}

return resolve(processedData)
Expand Down Expand Up @@ -502,9 +519,7 @@ class Nlu {
* 6. [OK] Handle a "loop" feature from action (guess the number)
* 7. [OK] While in an action loop, if something other than an expected entity is sent
* then break the loop. Need "loop" object in NLU skill config to describe
* 8. Make difference between actions to trigger immediately vs context to prepare
* 8.a. For the setup action, replace "next_action": "setup" by "action_to_trigger": "setup"
* 8.b. Keep next_action for the ones where context needs to be prepared ahead
* 8. [OK] Replay with the original utterance
* 9. Be able to use the loop without necessarily need slots
* 10. Split this process() method into several ones + clean nlu.js and brain.js
* 11. Add logs in terminal about context switching, active context, etc.
Expand Down
22 changes: 9 additions & 13 deletions skills/games/guess_the_number/nlu/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,19 +50,15 @@
"next_action": "replay"
},
"replay": {
"type": "dialog",
"slots": [
{
"name": "decision",
"item": {
"type": "resolver",
"name": "affirm_deny"
},
"questions": [
"Would you like to play another round?"
]
}
]
"type": "logic",
"loop": {
"expected_items": [
{
"type": "entity",
"name": "number"
}
]
}
}
},
"answers": {
Expand Down
2 changes: 1 addition & 1 deletion skills/games/guess_the_number/src/actions/guess.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def guess(params):
return utils.output('end', None, None, { 'isInActionLoop': False })

if given_nb == nb_to_guess:
return utils.output('end', 'guessed', '....CONGRATS....', { 'isInActionLoop': False })
return utils.output('end', 'guessed', '....CONGRATS.... Do you want to play another round?', { 'isInActionLoop': False })
if nb_to_guess < given_nb:
return utils.output('end', 'smaller', utils.translate('smaller'))
if nb_to_guess > given_nb:
Expand Down
25 changes: 25 additions & 0 deletions skills/games/guess_the_number/src/actions/replay.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#!/usr/bin/env python
# -*- coding:utf-8 -*-

import utils

def replay(params):
"""This is a test"""

entities, slots = params['entities'], params['slots']
decision = 0

# Find entities
# TODO: replace with confirmation resolver
for item in params['entities']:
if item['entity'] == 'number':
decision = item['resolution']['value']

if decision == 1:
return utils.output('end', 'replay', 'Let\'s goooo', {
'isInActionLoop': False,
'restart': True
})


return utils.output('end', 'quit', 'As you wish', { 'isInActionLoop': False })

0 comments on commit f4446ef

Please sign in to comment.