mirror of
https://github.com/leon-ai/leon.git
synced 2024-11-10 06:47:53 +03:00
feat(server): restart a skill with the original utterance saved in context
This commit is contained in:
parent
035c9d5240
commit
f4446ef177
@ -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)
|
||||
@ -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.
|
||||
|
@ -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": {
|
||||
|
@ -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:
|
||||
|
25
skills/games/guess_the_number/src/actions/replay.py
Normal file
25
skills/games/guess_the_number/src/actions/replay.py
Normal file
@ -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 })
|
Loading…
Reference in New Issue
Block a user