1
1
mirror of https://github.com/leon-ai/leon.git synced 2024-11-27 08:06:03 +03:00

feat(server): more accurate NLG

This commit is contained in:
louistiti 2022-02-28 22:54:31 +08:00
parent 28efe6e7d5
commit d5577b1ef5
No known key found for this signature in database
GPG Key ID: 0A1C3B043E70C77D
8 changed files with 56 additions and 17 deletions

View File

@ -10,6 +10,11 @@
"route": "/api/action/leon/color/color_meaning",
"params": []
},
{
"method": "GET",
"route": "/api/action/leon/color/specific_color_meaning",
"params": []
},
{
"method": "GET",
"route": "/api/action/leon/color/why",

View File

@ -324,7 +324,8 @@ class Brain {
)
const { entities, actions } = JSON.parse(fs.readFileSync(nluFilePath, 'utf8'))
const utteranceHasEntities = obj.entities.length > 0
let { answers } = obj
const { answers: rawAnswers } = obj
let answers = rawAnswers
let answer = ''
if (!utteranceHasEntities) {
@ -333,10 +334,15 @@ class Brain {
answers = answers.filter(({ answer }) => answer.indexOf('{{') !== -1)
}
// No required entity found, hence need to fallback to the "unknown_answers"
// When answers are simple without required entity
if (answers.length === 0) {
answers = actions[obj.classification.action]?.unknown_answers
answer = answers[Math.floor(Math.random() * answers.length)]
answer = rawAnswers[Math.floor(Math.random() * rawAnswers.length)]?.answer
// In case the expected answer requires a known entity
if (answer.indexOf('{{') !== -1) {
answers = actions[obj.classification.action]?.unknown_answers
answer = answers[Math.floor(Math.random() * answers.length)]
}
} else {
answer = answers[Math.floor(Math.random() * answers.length)]?.answer
@ -370,7 +376,21 @@ class Brain {
}
}
console.log('answer', answer)
const executionTimeEnd = Date.now()
const executionTime = executionTimeEnd - executionTimeStart
if (!opts.mute) {
this.talk(answer, true)
this._socket.emit('is-typing', false)
}
resolve({
utteranceId,
lang: this._lang,
...obj,
speeches: [answer],
executionTime // In ms, skill execution time only
})
}
}
})

View File

@ -186,7 +186,6 @@ class Nlu {
processingTime - data?.executionTime // In ms, NLU processing time only
})
} catch (e) /* istanbul ignore next */ {
console.error('eee', e)
log[e.type](e.obj.message)
if (!opts.mute) {

View File

@ -21,13 +21,26 @@
"color_meaning": {
"utterance_samples": [
"Tell me something about colors",
"Tell me something about the @color color",
"I want to know about the @color colour",
"How about the @color colour?"
"I want to know about colours",
"Share your knowledge about colors in general",
"Can you speak about colours?"
],
"answers": [
"Well, colors are used to differentiate and bring more aesthetic. Life is colorful!",
"Alright, here is for the {{ color }} color: {{ color.usage }}"
"Well, colors are used to differentiate and bring more aesthetic. Life is colorful!"
]
},
"specific_color_meaning": {
"utterance_samples": [
"Tell me something about the @color color",
"I want to know about the @color colour",
"How about the @color colour?",
"Can you tell me more about the @color color?"
],
"answers": [
"Alright, here is for the {{ color }} color: {{ color.usage }}."
],
"unknown_answers": [
"This color looks incredible, but I haven't seen it before."
]
},
"why": {

View File

@ -21,6 +21,5 @@
"Is your name Wi-Fi? Because I'm feeling a connection."
]
}
},
"answers": { }
}
}

View File

@ -27,6 +27,5 @@
"De nos jours, le zip ça devient rar..."
]
}
},
"answers": { }
}
}

View File

@ -12,8 +12,8 @@
"{{ partner_assistant.thought }}"
],
"unknown_answers": [
"I do not know this personal assistant",
"I have not met this personal assistant yet"
"I do not know this personal assistant.",
"I have not met this personal assistant yet."
]
}
},

View File

@ -10,6 +10,10 @@
],
"answers": [
"{{ partner_assistant.thought }}"
],
"unknown_answers": [
"Je ne connais pas cet assistant personnel.",
"Je n'ai pas encore rencontré cet assistant personnel."
]
}
},