mirror of
https://github.com/leon-ai/leon.git
synced 2024-11-27 16:16:48 +03:00
feat: support dynamic variables on skill NLU settings for logic type
This commit is contained in:
parent
c5edf6488b
commit
10d10a1690
@ -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"""
|
||||
|
||||
@ -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)
|
||||
|
@ -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": []
|
||||
},
|
||||
{
|
||||
@ -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",
|
||||
|
@ -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]
|
||||
|
@ -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,
|
||||
|
@ -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?",
|
||||
@ -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,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": "louis.grenard@gmail.com",
|
||||
|
14
skills/leon/introduction/src/actions/introduce_leon.py
Normal file
14
skills/leon/introduction/src/actions/introduce_leon.py
Normal file
@ -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,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"""
|
||||
|
@ -1,20 +0,0 @@
|
||||
{
|
||||
"actions": {
|
||||
"run": {
|
||||
"type": "dialog",
|
||||
"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"
|
||||
],
|
||||
"answers": [
|
||||
"I'm your daily personal assistant. I have been created by Louis. I'm very happy to serve you everyday.",
|
||||
"The question is, who are you? I'm kidding! I'm your daily personal assistant. Louis created me to make your life easier.",
|
||||
"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."
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
@ -1,20 +0,0 @@
|
||||
{
|
||||
"actions": {
|
||||
"run": {
|
||||
"type": "dialog",
|
||||
"utterance_samples": [
|
||||
"Qui es-tu ?",
|
||||
"Comment t'appelles-tu ?",
|
||||
"Comment tu t'appelles ?",
|
||||
"Dis-moi qui tu es",
|
||||
"Présente-toi",
|
||||
"Je veux te connaître"
|
||||
],
|
||||
"answers": [
|
||||
"Je suis votre assistant personnel quotidien. J'ai été créé par Louis. Je suis heureux de vous servir chaque jour.",
|
||||
"La question est plutôt qui êtes-vous ? Je plaisante ! Je suis votre assistant personnel quotidien. Louis m'a conçu pour rendre votre vie plus facile.",
|
||||
"Premièrement, je ne suis pas un criminel comme vous pouvez le penser au sujet d'un film populaire. Deuxièmement, Louis est celui qui m'a donné la vie. Troisièmement, je suis votre assistant personnel et je suis honoré de vous aider."
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
@ -1,11 +0,0 @@
|
||||
{
|
||||
"name": "Who Am I",
|
||||
"bridge": null,
|
||||
"version": "1.0.0",
|
||||
"description": "Leon introduces himself.",
|
||||
"author": {
|
||||
"name": "Louis Grenard",
|
||||
"email": "louis.grenard@gmail.com",
|
||||
"url": "https://github.com/louistiti"
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user