1
1
mirror of https://github.com/leon-ai/leon.git synced 2024-12-25 17:54:43 +03:00

feat(server): support dialog type action after slots filled

This commit is contained in:
louistiti 2024-04-29 18:02:41 +08:00
parent d9f0144e62
commit c934d0e30d
No known key found for this signature in database
GPG Key ID: 92CD6A2E497E1669
5 changed files with 79 additions and 56 deletions

View File

@ -2,130 +2,130 @@
"$schema": "../../../../schemas/global-data/global-entity.json", "$schema": "../../../../schemas/global-data/global-entity.json",
"options": { "options": {
"en-US": { "en-US": {
"synonyms": ["english", "british", "american"] "synonyms": ["English", "British", "American"]
}, },
"zh-CN": { "zh-CN": {
"synonyms": ["mandarin", "chinese"] "synonyms": ["Mandarin", "Chinese"]
}, },
"hi-IN": { "hi-IN": {
"synonyms": ["hindi", "indian"] "synonyms": ["Hindi", "Indian"]
}, },
"es-ES": { "es-ES": {
"synonyms": ["spanish"] "synonyms": ["Spanish"]
}, },
"fr-FR": { "fr-FR": {
"synonyms": ["french"] "synonyms": ["French"]
}, },
"ar-SA": { "ar-SA": {
"synonyms": ["arabic"] "synonyms": ["Arabic"]
}, },
"ru-RU": { "ru-RU": {
"synonyms": ["russian"] "synonyms": ["Russian"]
}, },
"pt-PT": { "pt-PT": {
"synonyms": ["portuguese"] "synonyms": ["Portuguese"]
}, },
"bn-IN": { "bn-IN": {
"synonyms": ["bengali"] "synonyms": ["Bengali"]
}, },
"in-ID": { "in-ID": {
"synonyms": ["indonesian"] "synonyms": ["Indonesian"]
}, },
"ja-JP": { "ja-JP": {
"synonyms": ["japanese"] "synonyms": ["Japanese"]
}, },
"de-DE": { "de-DE": {
"synonyms": ["german"] "synonyms": ["German"]
}, },
"ko-KR": { "ko-KR": {
"synonyms": ["korean"] "synonyms": ["Korean"]
}, },
"tr-TR": { "tr-TR": {
"synonyms": ["turkish"] "synonyms": ["Turkish"]
}, },
"it-IT": { "it-IT": {
"synonyms": ["italian"] "synonyms": ["Italian"]
}, },
"vi-VN": { "vi-VN": {
"synonyms": ["vietnamese"] "synonyms": ["Vietnamese"]
}, },
"th-TH": { "th-TH": {
"synonyms": ["thai"] "synonyms": ["Thai"]
}, },
"nl-NL": { "nl-NL": {
"synonyms": ["dutch"] "synonyms": ["Dutch"]
}, },
"pl-PL": { "pl-PL": {
"synonyms": ["polish"] "synonyms": ["Polish"]
}, },
"sv-SE": { "sv-SE": {
"synonyms": ["swedish"] "synonyms": ["Swedish"]
}, },
"da-DK": { "da-DK": {
"synonyms": ["danish"] "synonyms": ["Danish"]
}, },
"fi-FI": { "fi-FI": {
"synonyms": ["finnish"] "synonyms": ["Finnish"]
}, },
"no-NO": { "no-NO": {
"synonyms": ["norwegian"] "synonyms": ["Norwegian"]
}, },
"cs-CZ": { "cs-CZ": {
"synonyms": ["czech"] "synonyms": ["Czech"]
}, },
"hu-HU": { "hu-HU": {
"synonyms": ["hungarian"] "synonyms": ["Hungarian"]
}, },
"el-GR": { "el-GR": {
"synonyms": ["greek"] "synonyms": ["Greek"]
}, },
"ro-RO": { "ro-RO": {
"synonyms": ["romanian"] "synonyms": ["Romanian"]
}, },
"uk-UA": { "uk-UA": {
"synonyms": ["ukrainian"] "synonyms": ["Ukrainian"]
}, },
"hr-HR": { "hr-HR": {
"synonyms": ["croatian"] "synonyms": ["Croatian"]
}, },
"sr-RS": { "sr-RS": {
"synonyms": ["serbian"] "synonyms": ["Serbian"]
}, },
"bg-BG": { "bg-BG": {
"synonyms": ["bulgarian"] "synonyms": ["Bulgarian"]
}, },
"sk-SK": { "sk-SK": {
"synonyms": ["slovak"] "synonyms": ["Slovak"]
}, },
"sl-SI": { "sl-SI": {
"synonyms": ["slovenian"] "synonyms": ["Slovenian"]
}, },
"et-EE": { "et-EE": {
"synonyms": ["estonian"] "synonyms": ["Estonian"]
}, },
"lv-LV": { "lv-LV": {
"synonyms": ["latvian"] "synonyms": ["Latvian"]
}, },
"lt-LT": { "lt-LT": {
"synonyms": ["lithuanian"] "synonyms": ["Lithuanian"]
}, },
"mt-MT": { "mt-MT": {
"synonyms": ["maltese"] "synonyms": ["Maltese"]
}, },
"is-IS": { "is-IS": {
"synonyms": ["icelandic"] "synonyms": ["Icelandic"]
}, },
"mk-MK": { "mk-MK": {
"synonyms": ["macedonian"] "synonyms": ["Macedonian"]
}, },
"sq-AL": { "sq-AL": {
"synonyms": ["albanian"] "synonyms": ["Albanian"]
}, },
"bs-BA": { "bs-BA": {
"synonyms": ["bosnian"] "synonyms": ["Bosnian"]
}, },
"ur-PK": { "ur-PK": {
"synonyms": ["urdu"] "synonyms": ["Urdu"]
} }
} }
} }

View File

@ -251,6 +251,11 @@
"route": "/api/action/utilities/translator-poc/setup", "route": "/api/action/utilities/translator-poc/setup",
"params": [] "params": []
}, },
{
"method": "GET",
"route": "/api/action/utilities/translator-poc/ready",
"params": []
},
{ {
"method": "GET", "method": "GET",
"route": "/api/action/utilities/translator-poc/translate", "route": "/api/action/utilities/translator-poc/translate",

View File

@ -106,6 +106,11 @@ export default class Brain {
LogHelper.title('Brain') LogHelper.title('Brain')
LogHelper.info('Talking...') LogHelper.info('Talking...')
if (!answer) {
LogHelper.warning('No answer to say')
return
}
if (answer !== '') { if (answer !== '') {
const textAnswer = typeof answer === 'string' ? answer : answer.text const textAnswer = typeof answer === 'string' ? answer : answer.text
const speechAnswer = typeof answer === 'string' ? answer : answer.speech const speechAnswer = typeof answer === 'string' ? answer : answer.speech

View File

@ -73,6 +73,7 @@ export class SlotFilling {
...DEFAULT_NLU_RESULT, // Reset entities, slots, etc. ...DEFAULT_NLU_RESULT, // Reset entities, slots, etc.
utterance, utterance,
newUtterance: utterance, newUtterance: utterance,
skillConfigPath,
classification: { classification: {
domain, domain,
skill: skillName, skill: skillName,
@ -110,12 +111,19 @@ export class SlotFilling {
if (!NLU.conversation.areSlotsAllFilled()) { if (!NLU.conversation.areSlotsAllFilled()) {
BRAIN.talk(`${BRAIN.wernicke('random_context_out_of_topic')}.`) BRAIN.talk(`${BRAIN.wernicke('random_context_out_of_topic')}.`)
} else { } else {
const { actions } = await SkillDomainHelper.getSkillConfig(
skillConfigPath,
BRAIN.lang
)
const nextActionName = NLU.conversation.activeContext.nextAction
const hasNextAction = !!nextActionName
const doesNextActionHaveAnswers =
!!actions[NLU.conversation.activeContext.nextAction]?.answers
NLU.nluResult = { NLU.nluResult = {
...DEFAULT_NLU_RESULT, // Reset entities, slots, etc. ...DEFAULT_NLU_RESULT, // Reset entities, slots, etc.
// Assign slots only if there is a next action // Assign slots only if there is a next action
slots: NLU.conversation.activeContext.nextAction slots: hasNextAction ? NLU.conversation.activeContext.slots : {},
? NLU.conversation.activeContext.slots
: {},
utterance: NLU.conversation.activeContext.originalUtterance ?? '', utterance: NLU.conversation.activeContext.originalUtterance ?? '',
newUtterance: utterance, newUtterance: utterance,
skillConfigPath, skillConfigPath,
@ -124,18 +132,19 @@ export class SlotFilling {
skill: skillName, skill: skillName,
action: NLU.conversation.activeContext.nextAction, action: NLU.conversation.activeContext.nextAction,
confidence: 1 confidence: 1
} },
// Prepare answers if the next action has them
answers:
hasNextAction && doesNextActionHaveAnswers
? (actions[nextActionName]?.answers?.map((answer) => ({
answer
})) as { answer: string }[])
: []
} }
const processedData = await BRAIN.execute(NLU.nluResult) const processedData = await BRAIN.execute(NLU.nluResult)
/** NLU.conversation.cleanActiveContext()
* Clean active context if the skill action returns isInActionLoop as false
* to avoid looping indefinitely in the same action once all slots have been filled
*/
if (processedData.core?.isInActionLoop === false) {
NLU.conversation.cleanActiveContext()
}
return processedData return processedData
} }

View File

@ -17,10 +17,14 @@
] ]
} }
], ],
"next_action": "ready"
},
"ready": {
"type": "dialog",
"answers": [ "answers": [
"Let's start translating to %target_language%.", "Let's start translating to {{ target_language }}.",
"Okay, you can input the text you want to translate.", "Okay, you can input the text you want to translate to {{ target_language }}.",
"Alright, let's start translating to %target_language%." "Alright, let's start translating to {{ target_language }}."
], ],
"next_action": "translate" "next_action": "translate"
}, },