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:
parent
28efe6e7d5
commit
d5577b1ef5
@ -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",
|
||||
|
@ -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
|
||||
})
|
||||
}
|
||||
}
|
||||
})
|
||||
|
@ -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) {
|
||||
|
@ -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": {
|
||||
|
@ -21,6 +21,5 @@
|
||||
"Is your name Wi-Fi? Because I'm feeling a connection."
|
||||
]
|
||||
}
|
||||
},
|
||||
"answers": { }
|
||||
}
|
||||
}
|
||||
|
@ -27,6 +27,5 @@
|
||||
"De nos jours, le zip ça devient rar..."
|
||||
]
|
||||
}
|
||||
},
|
||||
"answers": { }
|
||||
}
|
||||
}
|
||||
|
@ -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."
|
||||
]
|
||||
}
|
||||
},
|
||||
|
@ -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."
|
||||
]
|
||||
}
|
||||
},
|
||||
|
Loading…
Reference in New Issue
Block a user