1
1
mirror of https://github.com/leon-ai/leon.git synced 2024-09-11 10:25:40 +03:00

feat: map skills resolvers intents

This commit is contained in:
louistiti 2022-07-01 01:07:48 +08:00
parent 82df0a3c23
commit eb5ade7684
No known key found for this signature in database
GPG Key ID: 7ECA3DD523793FE6
4 changed files with 33 additions and 12 deletions

View File

@ -22,7 +22,7 @@ export default (lang, nlp) => new Promise((resolve) => {
for (let j = 0; j < intentKeys.length; j += 1) {
const intentName = intentKeys[j]
const intent = `resolver.global.${intentName}`
const intent = `resolver.global.${resolverName}.${intentName}`
const intentObj = resolverIntents[intentName]
nlp.assignDomain(lang, intent, 'system')

View File

@ -34,7 +34,7 @@ export default (lang, nlp) => new Promise(async (resolve) => {
log.info(`[${lang}] Training "${resolverName}" resolver...`)
intentKeys.forEach((intentName) => {
const intent = `resolver.${currentSkill.name}.${intentName}`
const intent = `resolver.${currentSkill.name}.${resolverName}.${intentName}`
const intentObj = resolver.intents[intentName]
nlp.assignDomain(lang, intent, currentDomain.name)

View File

@ -223,7 +223,7 @@ class Nlu {
this.nluResultObj
)
const { actions } = JSON.parse(fs.readFileSync(nluDataFilePath, 'utf8'))
const { actions, resolvers } = JSON.parse(fs.readFileSync(nluDataFilePath, 'utf8'))
const action = actions[this.nluResultObj.classification.action]
const {
name: expectedItemName, type: expectedItemType
@ -235,17 +235,38 @@ class Nlu {
hasMatchingEntity = this.nluResultObj
.entities.filter(({ entity }) => expectedItemName === entity).length > 0
} else if (expectedItemType === 'resolver') {
const { intent } = await this.resolversNlp.process(utterance)
const result = await this.resolversNlp.process(utterance)
const { classifications } = result
let { intent } = result
/**
* Prioritize skill resolvers in the classification
* to not overlap with resolvers from other skills
*/
if (this.conv.hasActiveContext()) {
classifications.forEach(({ intent: newIntent, score: newScore }) => {
if (newScore > 0.6) {
const [, skillName] = newIntent.split('.')
if (this.nluResultObj.classification.skill === skillName) {
intent = newIntent
}
}
})
}
const resolveResolvers = (resolver, intent) => {
const resolversPath = join(process.cwd(), 'core/data', this.brain.lang, 'global-resolvers')
const { intents } = JSON.parse(fs.readFileSync(join(resolversPath, `${resolver}.json`)))
// Load the skill resolver or the global resolver
const resolvedIntents = !intent.includes('resolver.global')
? resolvers[resolver]
: JSON.parse(fs.readFileSync(join(resolversPath, `${resolver}.json`)))
// E.g. resolver.global.denial -> denial
intent = intent.substring(intent.lastIndexOf('.') + 1)
return [{
name: expectedItemName,
value: intents[intent].value
value: resolvedIntents.intents[intent].value
}]
}

View File

@ -15,13 +15,13 @@
"loop": {
"expected_item": {
"type": "resolver",
"name": "mbti_quiz"
"name": "form"
}
}
}
},
"resolvers": {
"mbti_quiz": {
"form": {
"intents": {
"1_a": {
"utterance_samples": [
@ -41,8 +41,8 @@
"2_a": {
"utterance_samples": [
"Realistic than speculative",
"I'm not a dreamer",
"I believe in science"
"Not a dreamer",
"Believe in science"
],
"value": "2_a"
},
@ -50,8 +50,8 @@
"utterance_samples": [
"Speculative than realistic",
"Speculative",
"I [like|love] to dream",
"I am a dreamer"
"[like|love] to dream",
"A dreamer"
],
"value": "2_b"
}