Skip to content

Commit

Permalink
feat(server): stop action loop from skill to core
Browse files Browse the repository at this point in the history
  • Loading branch information
louistiti committed May 5, 2022
1 parent c5b3840 commit 99681e2
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 25 deletions.
3 changes: 2 additions & 1 deletion bridges/python/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ def translate(key, d = { }):

return output

def output(type, code, speech = ''):
def output(type, code, speech = '', core = { }):
"""Communicate with the core"""

codes.append(code)
Expand All @@ -68,6 +68,7 @@ def output(type, code, speech = ''):
'type': type,
'codes': codes,
'speech': speech,
'core': core,
'options': config('options')
}
}))
Expand Down
4 changes: 4 additions & 0 deletions server/src/core/brain.js
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,8 @@ class Brain {
if (this.finalOutput !== '') {
this.finalOutput = JSON.parse(this.finalOutput).output

console.log('[BRAIN] this.finalOutput', this.finalOutput)

const speech = this.finalOutput.speech.toString()
if (!opts.mute) {
this.talk(speech, true)
Expand Down Expand Up @@ -319,6 +321,7 @@ class Brain {
lang: this._lang,
...obj,
speeches,
core: this.finalOutput.core,
executionTime // In ms, skill execution time only
})
})
Expand Down Expand Up @@ -397,6 +400,7 @@ class Brain {
lang: this._lang,
...obj,
speeches: [answer],
core: this.finalOutput.core,
executionTime // In ms, skill execution time only
})
}
Expand Down
2 changes: 2 additions & 0 deletions server/src/core/conversation.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ class Conversation {
* Activate context according to the triggered action
*/
set activeContext (contextObj) {
console.log('set activeContext', contextObj)
const {
slots,
isInActionLoop,
Expand Down Expand Up @@ -107,6 +108,7 @@ class Conversation {
* as long as the skill is being used
*/
if (this._activeContext.name !== newContextName) {
console.log('activate new context')
// Activate new context
this._activeContext = {
name: newContextName,
Expand Down
32 changes: 9 additions & 23 deletions server/src/core/nlu.js
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,15 @@ class Nlu {
)

const processedData = await this.brain.execute(this.nluResultObj, { mute: opts.mute })

if (processedData.core?.isInActionLoop === false) {
this.conv.activeContext = {
...this.conv.activeContext,
isInActionLoop: false
}
}

console.log('isInActionLoop processedData', processedData)
return resolve(processedData)
}

Expand Down Expand Up @@ -371,29 +380,6 @@ class Nlu {
const data = await this.brain.execute(this.nluResultObj, { mute: opts.mute })

console.log('data', data)
// TODO: if there is a nextAction, then don't empty active context for next round?
// TODO: or name "nextAction" by something else such as "nextContext"?
// TODO: make difference between next action that needs to be immediately triggered
// TODO: and the one that just need to set the context

// TODO: remove the next if
if (data.classification.skill === 'guess_the_number') {
data.nextAction = 'guess'
// Set new context with the next action if there is one
if (data.nextAction) {
this.conv.activeContext = {
lang: this.brain.lang,
slots: { },
originalUtterance: data.utterance,
nluDataFilePath: data.nluDataFilePath,
actionName: data.nextAction,
domain: data.domain,
intent: `${data.classification.skill}.${data.nextAction}`,
entities: []
}
}
}

console.log('this.conv.activeContext', this.conv.activeContext)

const processingTimeEnd = Date.now()
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 @@ -17,7 +17,7 @@ def guess(params):
given_nb = item['resolution']['value']

if given_nb == nb_to_guess:
return utils.output('end', 'guessed', '....CONGRATS....')
return utils.output('end', 'guessed', '....CONGRATS....', { 'isInActionLoop': False })
if nb_to_guess < given_nb:
return utils.output('end', 'smaller', utils.translate('smaller'))
if nb_to_guess > given_nb:
Expand Down

0 comments on commit 99681e2

Please sign in to comment.