Skip to content

Commit

Permalink
feat(server): complete slot filling before triggering the next action
Browse files Browse the repository at this point in the history
  • Loading branch information
louistiti committed Mar 27, 2022
1 parent 77ebaf4 commit 9124687
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 23 deletions.
1 change: 1 addition & 0 deletions server/src/core/brain.js
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ class Brain {

/**
* Execute Python skills
* TODO: split into several methods
*/
execute (obj, opts) {
const executionTimeStart = Date.now()
Expand Down
40 changes: 25 additions & 15 deletions server/src/core/nlu.js
Original file line number Diff line number Diff line change
Expand Up @@ -135,23 +135,27 @@ class Nlu {
nluResultObj
)

this.conv.setSlots(this.brain.lang, entities)

// console.log('active context obj', this.conv.activeContext)
// console.log('nluResultObj', nluResultObj)

const notFilledSlot = this.conv.getNotFilledSlot()
/**
* Loop for questions if a slot hasn't been filled
* and at least an entity has been found
*/
if (notFilledSlot && entities.length > 0) {
this.brain.talk(notFilledSlot.pickedQuestion)
this.brain.socket.emit('is-typing', false)
// Continue to loop for questions if a slot has been filled correctly
let notFilledSlot = this.conv.getNotFilledSlot()
if (entities.length > 0) {
const hasMatch = entities.some(({ entity }) => entity === notFilledSlot.expectedEntity)

if (hasMatch) {
this.conv.setSlots(this.brain.lang, entities)

notFilledSlot = this.conv.getNotFilledSlot()
if (notFilledSlot && entities.length > 0) {
this.brain.talk(notFilledSlot.pickedQuestion)
this.brain.socket.emit('is-typing', false)

return resolve()
return resolve()
}
}
}

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

if (!this.conv.areSlotsAllFilled()) {
this.brain.talk(`${this.brain.wernicke('random_context_out_of_topic')}.`)
} else {
Expand All @@ -161,11 +165,17 @@ class Nlu {
* 2. [OK] If none of them match any slot in the active context, then continue
* 3. [OK] If an entity match slot in active context, then fill it
* 4. [OK] Move skill type to action type
* 5. Execute next action (based on input_context?)
* 5.1 In Conversation, need to chain output/input contexts to each other
* to understand what action should be next
* 5.2 Execute next action (based on input_context?)
* 5.3 Need to handle the case if a context is filled in one shot
* e.g. I wanna play with 2 players and louis.grenard@gmail.com
* 6. Split this process() method into several ones
* 7. Add logs in terminal about context switching, active context, etc.
*/

// TODO: recreate nluResultObj for the NEXT action (actionType, etc.)

const data = await this.brain.execute(nluResultObj, { mute: opts.mute })
return resolve({
...data
Expand Down
6 changes: 0 additions & 6 deletions skills/games/guess_the_number/nlu/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,6 @@
"pick_up": {
"type": "logic",
"input_context": "setup_game",
"utterance_samples": [
"I'm choosing 20",
"Number 38",
"I choose 73",
"86"
],
"answers": {
"bigger": [
"The number is bigger.",
Expand Down
4 changes: 2 additions & 2 deletions skills/games/guess_the_number/src/actions/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@
from random import randint

def run(string, entities):
"""Leon gives a random number"""
"""TODO..."""

return utils.output('end', 'success', randint(0, 100))
return utils.output('end', 'ready', utils.translate('ready')

0 comments on commit 9124687

Please sign in to comment.