Skip to content

Commit

Permalink
feat: support dynamic variables on skill NLU settings for logic type
Browse files Browse the repository at this point in the history
  • Loading branch information
louistiti committed Jun 12, 2022
1 parent c5edf64 commit 10d10a1
Show file tree
Hide file tree
Showing 14 changed files with 63 additions and 102 deletions.
13 changes: 9 additions & 4 deletions bridges/python/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ def get_intent_obj():

return intent_obj

def translate(key, d = { }):
def translate(key, dict = { }):
"""Pickup the language file according to the cmd arg
and return the value according to the params"""

Expand All @@ -38,14 +38,19 @@ def translate(key, d = { }):
file.close()

prop = obj['answers'][key]
variables = obj['variables']
if isinstance(prop, list):
output = choice(prop)
else:
output = prop

if d:
for k in d:
output = output.replace('%' + k + '%', str(d[k]))
if dict:
for key in dict:
output = output.replace('%' + key + '%', str(dict[key]))

if variables:
for key in variables:
output = output.replace('%' + key + '%', str(variables[key]))

# "Temporize" for the data buffer ouput on the core
sleep(0.1)
Expand Down
12 changes: 6 additions & 6 deletions core/skills-endpoints.json
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,12 @@
},
{
"method": "GET",
"route": "/api/action/leon/introduction/fill",
"route": "/api/action/leon/introduction/introduce_leon",
"params": []
},
{
"method": "GET",
"route": "/api/action/leon/introduction/gather_basic_info",
"params": []
},
{
Expand Down Expand Up @@ -118,11 +123,6 @@
"route": "/api/action/leon/welcome/run",
"params": []
},
{
"method": "GET",
"route": "/api/action/leon/who_am_i/run",
"params": []
},
{
"method": "POST",
"route": "/api/action/news/github_trends/run",
Expand Down
34 changes: 0 additions & 34 deletions scripts/train.js
Original file line number Diff line number Diff line change
Expand Up @@ -110,40 +110,6 @@ export default () => new Promise(async (resolve, reject) => {

nlp.assignDomain(lang, `${skillName}.${actionName}`, currentDomain.name)

/**
* TODO:
* 1. [OK] Merge person, location and organization to the
* NER before processing NLU (cf. line 210 in nlu.js)
* 2. [OK] Grab intents with slots
* 3. [OK] .addSlot() as per the slots config
* 4. [OK] Handle random questions picking
* srcAnswer has the array, need to activate context now?
* 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 [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. [OK] Train resolvers (affirm_deny: boolean value)
* 8. [OK] Map resolvers to skill actions
* 9. Utterance item 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 color or to do list 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. [OK] "Add potatoes to my shopping list" ... "Actually remove it"
* The entities are already persistent in context.
* Just need to check in current context and loop through classifications intent.
* If the skill is found, then use that intent. So an intent should not always be
* the one with the highest confidence
* 12. Modify skills as per new code (skill params became dictionary [OK], etc.)
*/
if (slots) {
for (let l = 0; l < slots.length; l += 1) {
const slotObj = slots[l]
Expand Down
8 changes: 5 additions & 3 deletions server/src/core/brain.js
Original file line number Diff line number Diff line change
Expand Up @@ -180,9 +180,11 @@ class Brain {
* python bridges/python/main.py server/src/intent-object.sample.json
*/
const slots = { }
Object.keys(obj.slots).forEach((slotName) => {
slots[slotName] = obj.slots[slotName].value
})
if (obj.slots) {
Object.keys(obj.slots)?.forEach((slotName) => {
slots[slotName] = obj.slots[slotName].value
})
}
const intentObj = {
id: utteranceId,
lang: this._lang,
Expand Down
29 changes: 28 additions & 1 deletion skills/leon/introduction/nlu/en.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,23 @@
{
"variables": {
"leon_introduction_1": "I'm your daily personal assistant. I have been created by Louis. I'm very happy to serve you everyday.",
"leon_introduction_2": "The question is, who are you? I'm kidding! I'm your daily personal assistant. Louis created me to make your life easier.",
"leon_introduction_3": "Firstly, I'm not a criminal as you might relatively think about a popular movie. Secondly, Louis is the guy who gave me life. Thirdly, I'm your personal assistant and I'm very glad to help you."
},
"actions": {
"fill": {
"introduce_leon": {
"type": "logic",
"utterance_samples": [
"Who are you?",
"How they call you?",
"What's your name?",
"Tell me who you are",
"Introduce yourself",
"I want to know you"
],
"next_action": "gather_basic_info"
},
"gather_basic_info": {
"type": "dialog",
"utterance_samples": [
"Do you know who am I?",
Expand Down Expand Up @@ -42,6 +59,16 @@
"remembered": [
"I'm going to remember that %owner_name%",
"Good to know a bit more about you %owner_name%"
],
"leon_introduction": [
"%leon_introduction_1%",
"%leon_introduction_2%",
"%leon_introduction_3%"
],
"leon_introduction_with_question": [
"%leon_introduction_1% How about you?",
"%leon_introduction_2% How about you?",
"%leon_introduction_3% How about you?"
]
}
}
2 changes: 1 addition & 1 deletion skills/leon/introduction/skill.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "Introduction",
"bridge": "python",
"version": "1.0.0",
"description": "Leon remembers basic information about you.",
"description": "Leon introduce himself and remembers basic information about you.",
"author": {
"name": "Louis Grenard",
"email": "[email protected]",
Expand Down
14 changes: 14 additions & 0 deletions skills/leon/introduction/src/actions/introduce_leon.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#!/usr/bin/env python
# -*- coding:utf-8 -*-

import utils

def introduce_leon(params):
"""TODO"""

has_info = True

if has_info == False:
return utils.output('end', 'remembered', utils.translate('remembered', { 'owner_name': owner_name }))

return utils.output('end', 'leon_introduction', utils.translate('leon_introduction'))
2 changes: 0 additions & 2 deletions skills/leon/introduction/src/actions/remember.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
# -*- coding:utf-8 -*-

import utils
from datetime import datetime
from random import randint

def remember(params):
"""Save name and birth date into Leon's memory"""
Expand Down
Empty file removed skills/leon/who_am_i/README.md
Empty file.
Empty file.
20 changes: 0 additions & 20 deletions skills/leon/who_am_i/nlu/en.json

This file was deleted.

20 changes: 0 additions & 20 deletions skills/leon/who_am_i/nlu/fr.json

This file was deleted.

11 changes: 0 additions & 11 deletions skills/leon/who_am_i/skill.json

This file was deleted.

Empty file removed skills/leon/who_am_i/test/.gitkeep
Empty file.

0 comments on commit 10d10a1

Please sign in to comment.