mirror of
https://github.com/leon-ai/leon.git
synced 2024-12-24 17:23:23 +03:00
feat(server): support dialog type action after slots filled
This commit is contained in:
parent
d9f0144e62
commit
c934d0e30d
@ -2,130 +2,130 @@
|
||||
"$schema": "../../../../schemas/global-data/global-entity.json",
|
||||
"options": {
|
||||
"en-US": {
|
||||
"synonyms": ["english", "british", "american"]
|
||||
"synonyms": ["English", "British", "American"]
|
||||
},
|
||||
"zh-CN": {
|
||||
"synonyms": ["mandarin", "chinese"]
|
||||
"synonyms": ["Mandarin", "Chinese"]
|
||||
},
|
||||
"hi-IN": {
|
||||
"synonyms": ["hindi", "indian"]
|
||||
"synonyms": ["Hindi", "Indian"]
|
||||
},
|
||||
"es-ES": {
|
||||
"synonyms": ["spanish"]
|
||||
"synonyms": ["Spanish"]
|
||||
},
|
||||
"fr-FR": {
|
||||
"synonyms": ["french"]
|
||||
"synonyms": ["French"]
|
||||
},
|
||||
"ar-SA": {
|
||||
"synonyms": ["arabic"]
|
||||
"synonyms": ["Arabic"]
|
||||
},
|
||||
"ru-RU": {
|
||||
"synonyms": ["russian"]
|
||||
"synonyms": ["Russian"]
|
||||
},
|
||||
"pt-PT": {
|
||||
"synonyms": ["portuguese"]
|
||||
"synonyms": ["Portuguese"]
|
||||
},
|
||||
"bn-IN": {
|
||||
"synonyms": ["bengali"]
|
||||
"synonyms": ["Bengali"]
|
||||
},
|
||||
"in-ID": {
|
||||
"synonyms": ["indonesian"]
|
||||
"synonyms": ["Indonesian"]
|
||||
},
|
||||
"ja-JP": {
|
||||
"synonyms": ["japanese"]
|
||||
"synonyms": ["Japanese"]
|
||||
},
|
||||
"de-DE": {
|
||||
"synonyms": ["german"]
|
||||
"synonyms": ["German"]
|
||||
},
|
||||
"ko-KR": {
|
||||
"synonyms": ["korean"]
|
||||
"synonyms": ["Korean"]
|
||||
},
|
||||
"tr-TR": {
|
||||
"synonyms": ["turkish"]
|
||||
"synonyms": ["Turkish"]
|
||||
},
|
||||
"it-IT": {
|
||||
"synonyms": ["italian"]
|
||||
"synonyms": ["Italian"]
|
||||
},
|
||||
"vi-VN": {
|
||||
"synonyms": ["vietnamese"]
|
||||
"synonyms": ["Vietnamese"]
|
||||
},
|
||||
"th-TH": {
|
||||
"synonyms": ["thai"]
|
||||
"synonyms": ["Thai"]
|
||||
},
|
||||
"nl-NL": {
|
||||
"synonyms": ["dutch"]
|
||||
"synonyms": ["Dutch"]
|
||||
},
|
||||
"pl-PL": {
|
||||
"synonyms": ["polish"]
|
||||
"synonyms": ["Polish"]
|
||||
},
|
||||
"sv-SE": {
|
||||
"synonyms": ["swedish"]
|
||||
"synonyms": ["Swedish"]
|
||||
},
|
||||
"da-DK": {
|
||||
"synonyms": ["danish"]
|
||||
"synonyms": ["Danish"]
|
||||
},
|
||||
"fi-FI": {
|
||||
"synonyms": ["finnish"]
|
||||
"synonyms": ["Finnish"]
|
||||
},
|
||||
"no-NO": {
|
||||
"synonyms": ["norwegian"]
|
||||
"synonyms": ["Norwegian"]
|
||||
},
|
||||
"cs-CZ": {
|
||||
"synonyms": ["czech"]
|
||||
"synonyms": ["Czech"]
|
||||
},
|
||||
"hu-HU": {
|
||||
"synonyms": ["hungarian"]
|
||||
"synonyms": ["Hungarian"]
|
||||
},
|
||||
"el-GR": {
|
||||
"synonyms": ["greek"]
|
||||
"synonyms": ["Greek"]
|
||||
},
|
||||
"ro-RO": {
|
||||
"synonyms": ["romanian"]
|
||||
"synonyms": ["Romanian"]
|
||||
},
|
||||
"uk-UA": {
|
||||
"synonyms": ["ukrainian"]
|
||||
"synonyms": ["Ukrainian"]
|
||||
},
|
||||
"hr-HR": {
|
||||
"synonyms": ["croatian"]
|
||||
"synonyms": ["Croatian"]
|
||||
},
|
||||
"sr-RS": {
|
||||
"synonyms": ["serbian"]
|
||||
"synonyms": ["Serbian"]
|
||||
},
|
||||
"bg-BG": {
|
||||
"synonyms": ["bulgarian"]
|
||||
"synonyms": ["Bulgarian"]
|
||||
},
|
||||
"sk-SK": {
|
||||
"synonyms": ["slovak"]
|
||||
"synonyms": ["Slovak"]
|
||||
},
|
||||
"sl-SI": {
|
||||
"synonyms": ["slovenian"]
|
||||
"synonyms": ["Slovenian"]
|
||||
},
|
||||
"et-EE": {
|
||||
"synonyms": ["estonian"]
|
||||
"synonyms": ["Estonian"]
|
||||
},
|
||||
"lv-LV": {
|
||||
"synonyms": ["latvian"]
|
||||
"synonyms": ["Latvian"]
|
||||
},
|
||||
"lt-LT": {
|
||||
"synonyms": ["lithuanian"]
|
||||
"synonyms": ["Lithuanian"]
|
||||
},
|
||||
"mt-MT": {
|
||||
"synonyms": ["maltese"]
|
||||
"synonyms": ["Maltese"]
|
||||
},
|
||||
"is-IS": {
|
||||
"synonyms": ["icelandic"]
|
||||
"synonyms": ["Icelandic"]
|
||||
},
|
||||
"mk-MK": {
|
||||
"synonyms": ["macedonian"]
|
||||
"synonyms": ["Macedonian"]
|
||||
},
|
||||
"sq-AL": {
|
||||
"synonyms": ["albanian"]
|
||||
"synonyms": ["Albanian"]
|
||||
},
|
||||
"bs-BA": {
|
||||
"synonyms": ["bosnian"]
|
||||
"synonyms": ["Bosnian"]
|
||||
},
|
||||
"ur-PK": {
|
||||
"synonyms": ["urdu"]
|
||||
"synonyms": ["Urdu"]
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -251,6 +251,11 @@
|
||||
"route": "/api/action/utilities/translator-poc/setup",
|
||||
"params": []
|
||||
},
|
||||
{
|
||||
"method": "GET",
|
||||
"route": "/api/action/utilities/translator-poc/ready",
|
||||
"params": []
|
||||
},
|
||||
{
|
||||
"method": "GET",
|
||||
"route": "/api/action/utilities/translator-poc/translate",
|
||||
|
@ -106,6 +106,11 @@ export default class Brain {
|
||||
LogHelper.title('Brain')
|
||||
LogHelper.info('Talking...')
|
||||
|
||||
if (!answer) {
|
||||
LogHelper.warning('No answer to say')
|
||||
return
|
||||
}
|
||||
|
||||
if (answer !== '') {
|
||||
const textAnswer = typeof answer === 'string' ? answer : answer.text
|
||||
const speechAnswer = typeof answer === 'string' ? answer : answer.speech
|
||||
|
@ -73,6 +73,7 @@ export class SlotFilling {
|
||||
...DEFAULT_NLU_RESULT, // Reset entities, slots, etc.
|
||||
utterance,
|
||||
newUtterance: utterance,
|
||||
skillConfigPath,
|
||||
classification: {
|
||||
domain,
|
||||
skill: skillName,
|
||||
@ -110,12 +111,19 @@ export class SlotFilling {
|
||||
if (!NLU.conversation.areSlotsAllFilled()) {
|
||||
BRAIN.talk(`${BRAIN.wernicke('random_context_out_of_topic')}.`)
|
||||
} 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 = {
|
||||
...DEFAULT_NLU_RESULT, // Reset entities, slots, etc.
|
||||
// Assign slots only if there is a next action
|
||||
slots: NLU.conversation.activeContext.nextAction
|
||||
? NLU.conversation.activeContext.slots
|
||||
: {},
|
||||
slots: hasNextAction ? NLU.conversation.activeContext.slots : {},
|
||||
utterance: NLU.conversation.activeContext.originalUtterance ?? '',
|
||||
newUtterance: utterance,
|
||||
skillConfigPath,
|
||||
@ -124,18 +132,19 @@ export class SlotFilling {
|
||||
skill: skillName,
|
||||
action: NLU.conversation.activeContext.nextAction,
|
||||
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)
|
||||
|
||||
/**
|
||||
* 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()
|
||||
}
|
||||
NLU.conversation.cleanActiveContext()
|
||||
|
||||
return processedData
|
||||
}
|
||||
|
@ -17,10 +17,14 @@
|
||||
]
|
||||
}
|
||||
],
|
||||
"next_action": "ready"
|
||||
},
|
||||
"ready": {
|
||||
"type": "dialog",
|
||||
"answers": [
|
||||
"Let's start translating to %target_language%.",
|
||||
"Okay, you can input the text you want to translate.",
|
||||
"Alright, let's start translating to %target_language%."
|
||||
"Let's start translating to {{ target_language }}.",
|
||||
"Okay, you can input the text you want to translate to {{ target_language }}.",
|
||||
"Alright, let's start translating to {{ target_language }}."
|
||||
],
|
||||
"next_action": "translate"
|
||||
},
|
||||
|
Loading…
Reference in New Issue
Block a user