Skip to content

Commit

Permalink
feat: better isolate skill resolvers from global resolvers + finish u…
Browse files Browse the repository at this point in the history
…p Akinator skill
  • Loading branch information
louistiti committed Jul 10, 2022
1 parent b35a249 commit 905d248
Show file tree
Hide file tree
Showing 10 changed files with 95 additions and 25 deletions.
2 changes: 1 addition & 1 deletion core/skills-endpoints.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
},
{
"method": "GET",
"route": "/api/action/games/akinator/replay",
"route": "/api/action/games/akinator/retry",
"params": []
},
{
Expand Down
18 changes: 11 additions & 7 deletions server/src/core/nlu.js
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ class Nlu {
if (expectedItemType === 'entity') {
hasMatchingEntity = this.nluResultObj
.entities.filter(({ entity }) => expectedItemName === entity).length > 0
} else if (expectedItemType === 'resolver') {
} else if (expectedItemType.indexOf('resolver') !== -1) {
const result = await this.resolversNlp.process(utterance)
const { classifications } = result
let { intent } = result
Expand All @@ -247,15 +247,19 @@ class Nlu {
const classification = classifications.find(({ intent: newIntent, score: newScore }) => {
const [, skillName] = newIntent.split('.')

// Prioritize skill resolver intent
if (newScore > 0.6) {
if (this.nluResultObj.classification.skill === skillName) {
return true
if (expectedItemType === 'skill_resolver') {
// Prioritize skill resolver intent
if (newScore > 0.6) {
return this.nluResultObj.classification.skill === skillName
}
}

// Use a global resolver if any
return skillName === 'global'
if (expectedItemType === 'global_resolver') {
// Use a global resolver if any
return skillName === 'global'
}

return false
})
// eslint-disable-next-line prefer-destructuring
intent = classification?.intent
Expand Down
47 changes: 42 additions & 5 deletions skills/games/akinator/nlu/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -57,13 +57,24 @@
"type": "logic",
"loop": {
"expected_item": {
"type": "resolver",
"type": "skill_resolver",
"name": "answer"
}
}
},
"suggestions": [
"Yes",
"No thanks"
],
"next_action": "retry"
},
"replay": {
"type": "logic"
"retry": {
"type": "logic",
"loop": {
"expected_item": {
"type": "global_resolver",
"name": "affirmation_denial"
}
}
}
},
"resolvers": {
Expand All @@ -86,7 +97,9 @@
"idk": {
"utterance_samples": [
"I do not know",
"Don't know",
"Do not know",
"[Dont|Don't] know",
"No idea",
"Not sure"
],
"value": "idk"
Expand All @@ -108,5 +121,29 @@
}
},
"answers": {
"calling_akinator": [
"I'm calling my friend Akinator...",
"Alright, let me call Akinator, wait a sec...",
"Sure, let me get in touch with Akinator. Please wait a sec..."
],
"guessed": [
"I take the shot, you are thinking of %name%. %description%.",
"I guess you think of %name%. %description%."
],
"guessed_img": [
"<img src=\"%url%\" alt=\"%name%\" style=\"max-width:200px\" />"
],
"ask_for_retry": [
"Do you want to go for another one?",
"Should we go for another try?"
],
"confirm_retry": [
"Gotcha!",
"Let's go for another try then!"
],
"deny_retry": [
"Got it, take care.",
"Let me know anytime you want I call Akinator."
]
}
}
16 changes: 14 additions & 2 deletions skills/games/akinator/src/actions/guess.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ def guess(params):
resolvers = params['resolvers']
answer = None

return utils.output('end', 'ask_for_retry', { 'isInActionLoop': False })

for resolver in resolvers:
if resolver['name'] == 'answer':
answer = resolver['value']
Expand Down Expand Up @@ -40,8 +42,18 @@ def guess(params):

if session['progression'] > 80:
aki.win()
# name; description; absolute_picture_path
return utils.output('end', aki.first_guess['name'])

utils.output('inter', { 'key': 'guessed', 'data': {
'name': aki.first_guess['name'],
'description': aki.first_guess['description']
}})

utils.output('inter', { 'key': 'guessed_img', 'data': {
'name': aki.first_guess['name'],
'url': aki.first_guess['absolute_picture_path']
}}, { 'isInActionLoop': False })

return utils.output('end', 'ask_for_retry', { 'isInActionLoop': False })

aki.answer(answer)

Expand Down
7 changes: 0 additions & 7 deletions skills/games/akinator/src/actions/replay.py

This file was deleted.

22 changes: 22 additions & 0 deletions skills/games/akinator/src/actions/retry.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#!/usr/bin/env python
# -*- coding:utf-8 -*-

import utils

def retry(params):
"""Ask for a retry"""

resolvers = params['resolvers']
decision = False

for resolver in resolvers:
if resolver['name'] == 'affirmation_denial':
decision = resolver['value']

if decision == True:
return utils.output('end', 'confirm_retry', {
'isInActionLoop': False,
'restart': True
})

return utils.output('end', 'deny_retry', { 'isInActionLoop': False })
2 changes: 2 additions & 0 deletions skills/games/akinator/src/actions/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
def setup(params):
"""Initialize new session"""

utils.output('inter', 'calling_akinator')

slots, lang = params['slots'], params['lang']
thematic = slots['thematic']['resolution']['value']
theme_lang = lang
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 @@ -28,7 +28,7 @@
"type": "logic",
"loop": {
"expected_item": {
"type": "resolver",
"type": "global_resolver",
"name": "affirmation_denial"
}
}
Expand Down
2 changes: 1 addition & 1 deletion skills/games/rochambeau/nlu/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
"type": "logic",
"loop": {
"expected_item": {
"type": "resolver",
"type": "global_resolver",
"name": "affirmation_denial"
}
}
Expand Down
2 changes: 1 addition & 1 deletion skills/social_communication/mbti/nlu/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"type": "logic",
"loop": {
"expected_item": {
"type": "resolver",
"type": "skill_resolver",
"name": "form"
}
}
Expand Down

0 comments on commit 905d248

Please sign in to comment.