1
1
mirror of https://github.com/leon-ai/leon.git synced 2024-11-24 04:31:31 +03:00

feat(server): when a context is activated, pick up the most probable classification

This commit is contained in:
louistiti 2022-04-06 01:44:40 +08:00
parent 875757739f
commit 8e1868798c
No known key found for this signature in database
GPG Key ID: 0A1C3B043E70C77D
2 changed files with 31 additions and 8 deletions

View File

@ -111,8 +111,9 @@ export default () => new Promise(async (resolve, reject) => {
* > Well, the red color... * > Well, the red color...
* - Do you like this color? * - Do you like this color?
* > Red is cool, but I prefer... * > Red is cool, but I prefer...
* 11. "Add potatoes to my shopping list" ... "Actually remove it" * 11. [OK] "Add potatoes to my shopping list" ... "Actually remove it"
* Need to see in current context and loop through classifications intent. * 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 * If the skill is found, then use that intent. So an intent should not always be
* the one with the highest confidence * the one with the highest confidence
* 12. Modify skills as per new code (skill params became dictionary [OK], etc.) * 12. Modify skills as per new code (skill params became dictionary [OK], etc.)

View File

@ -139,10 +139,33 @@ class Nlu {
} }
const result = await this.nlp.process(utterance) const result = await this.nlp.process(utterance)
// console.log('result', result) console.log('result', result)
const { const {
locale, domain, intent, score, answers locale, answers, classifications
} = result } = result
let { score, intent, domain } = result
/**
* If a context is active, then use the appropriate classification based on score probability.
* E.g. 1. Create my shopping list; 2. Actually delete it.
* If there are several "delete it" across skills, Leon needs to make use of
* the current context ({domain}.{skill}) to define the most accurate classification
*/
if (this.conv.hasActiveContext()) {
classifications.forEach(({ intent: newIntent, score: newScore }) => {
if (newScore > 0.6) {
const [skillName] = newIntent.split('.')
const newDomain = this.nlp.getIntentDomain(locale, newIntent)
const contextName = `${newDomain}.${skillName}`
if (this.conv.activeContext.name === contextName) {
score = newScore
intent = newIntent
domain = newDomain
}
}
})
}
const [skillName, actionName] = intent.split('.') const [skillName, actionName] = intent.split('.')
this.nluResultObj = { this.nluResultObj = {
...this.nluResultObj, ...this.nluResultObj,
@ -370,11 +393,10 @@ class Nlu {
* 5.3 [OK] Need to handle the case if a context is filled in one shot * 5.3 [OK] Need to handle the case if a context is filled in one shot
* e.g. I wanna play with 2 players and louis.grenard@gmail.com * e.g. I wanna play with 2 players and louis.grenard@gmail.com
* Need to refactor now (nluResultObj method to build it, etc.) * Need to refactor now (nluResultObj method to build it, etc.)
* 6. What's next once the next action has been executed? * 6. Handle a "loop" feature from action (guess the number)
* 7. Handle a "loop" feature from action (guess the number)
* No need "loop" in the NLU skill config. Just add option in util output * No need "loop" in the NLU skill config. Just add option in util output
* 8. Split this process() method into several ones + clean nlu.js and brain.js * 7. Split this process() method into several ones + clean nlu.js and brain.js
* 9. Add logs in terminal about context switching, active context, etc. * 8. Add logs in terminal about context switching, active context, etc.
*/ */
this.nluResultObj = { this.nluResultObj = {