Skip to content

Commit

Permalink
feat(server): forward slots to skill + add original utterance
Browse files Browse the repository at this point in the history
  • Loading branch information
louistiti committed Mar 31, 2022
1 parent 22e9234 commit 68e40f6
Show file tree
Hide file tree
Showing 7 changed files with 32 additions and 10 deletions.
8 changes: 7 additions & 1 deletion bridges/python/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,13 @@ def main():

skill = import_module('skills.' + intent_obj['domain'] + '.' + intent_obj['skill'] + '.src.actions.' + intent_obj['action'])

return getattr(skill, intent_obj['action'])(intent_obj['utterance'], intent_obj['entities'])
params = {
'utterance': intent_obj['utterance'],
'entities': intent_obj['entities'],
'slots': intent_obj['slots']
}

return getattr(skill, intent_obj['action'])(params)

if __name__ == '__main__':
main()
16 changes: 11 additions & 5 deletions scripts/train.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,17 +89,23 @@ export default () => new Promise(async (resolve, reject) => {
* to detect we should pick .srcAnswer
* 5.1 [OK] Reorganize code before to proceed to next steps
* 5.2 [OK] Activate context and fill slots
* 5.3 Keep action activated in context + forward slot data to next action
* 6. Train resolvers (affirm_deny: boolean value)
* 7. Map resolvers to skill actions
* 8. Utterance source type to get raw input from utterance
* 9. Create superheroes skill (just for testing):
* 5.3 [OK] Keep action activated in context + forward slot data to next action
* 6. Make entities + slots way lighter with simple properties
* to be used in skills without too much properties and nested props.
* Currently: slots['players_nb']['value']['sourceText']
* Should be: slots['players_nb']['value']
* And possible: slots['players_nb']['sourceText']
* 7. Train resolvers (affirm_deny: boolean value)
* 8. Map resolvers to skill actions
* 9. Utterance source type to get raw input from utterance
* 10. Create superheroes skill (just for testing):
* to ask Leon questions by saving context
* or just use the colors skill?
* - I want to know about the red color
* > Well, the red color...
* - Do you like this color?
* > Red is cool, but I prefer...
* 11. Modify skills as per new code (skill params became dictionary, etc.)
*/
if (slots) {
for (let l = 0; l < slots.length; l += 1) {
Expand Down
3 changes: 2 additions & 1 deletion server/src/core/brain.js
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,8 @@ class Brain {
skill: obj.classification.skill,
action: obj.classification.action,
utterance: obj.utterance,
entities: obj.entities
entities: obj.entities,
slots: obj.slots
}

try {
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 @@ -8,6 +8,7 @@ const defaultActiveContext = {
intent: null,
slots: { },
nextAction: null,
originalUtterance: null,
activatedAt: 0
}

Expand Down Expand Up @@ -79,6 +80,7 @@ class Conversation {
intent,
slots: { },
nextAction,
originalUtterance: contextObj.originalUtterance,
activatedAt: Date.now()
}
}
Expand Down
2 changes: 2 additions & 0 deletions server/src/core/nlu.js
Original file line number Diff line number Diff line change
Expand Up @@ -359,6 +359,7 @@ class Nlu {
...this.nluResultObj,
// TODO: the brain needs to forward slots to the skill execution
slots: this.conv.activeContext.slots,
utterance: this.conv.activeContext.originalUtterance,
nluDataFilePath,
classification: {
domain,
Expand Down Expand Up @@ -388,6 +389,7 @@ class Nlu {
this.conv.activeContext = {
lang: this.brain.lang,
slots,
originalUtterance: this.nluResultObj.utterance,
nluDataFilePath: this.nluResultObj.nluDataFilePath,
actionName: this.nluResultObj.classification.action,
domain: this.nluResultObj.classification.domain,
Expand Down
2 changes: 1 addition & 1 deletion skills/games/guess_the_number/nlu/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@
},
"answers": {
"ready": [
"Alright, I'm ready, go ahead and guess the number between 0 and 100!"
"Alright, I have set %players_nb% players with the %email_test% email. Go ahead and guess the number between 0 and 100!"
]
}
}
9 changes: 7 additions & 2 deletions skills/games/guess_the_number/src/actions/pick_up.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,12 @@

import utils

def pick_up(string, entities):
def pick_up(params):
"""This is a test"""

return utils.output('end', 'ready', utils.translate('ready'))
entities, slots = params['entities'], params['slots']

return utils.output('end', 'ready', utils.translate('ready', {
'players_nb': slots['players_nb']['value']['sourceText'],
'email_test': slots['email_test']['value']['sourceText']
}))

0 comments on commit 68e40f6

Please sign in to comment.