1
1
mirror of https://github.com/leon-ai/leon.git synced 2024-12-01 03:15:58 +03:00

refactor(server): NLU default values

This commit is contained in:
louistiti 2023-04-02 16:56:53 +08:00
parent 8282c37a5a
commit 44882129a7

View File

@ -12,7 +12,7 @@ import { LogHelper } from '@/helpers/log-helper'
import { LangHelper } from '@/helpers/lang-helper' import { LangHelper } from '@/helpers/lang-helper'
import { ActionLoop } from '@/core/nlp/nlu/action-loop' import { ActionLoop } from '@/core/nlp/nlu/action-loop'
import { SlotFilling } from '@/core/nlp/nlu/slot-filling' import { SlotFilling } from '@/core/nlp/nlu/slot-filling'
import Conversation from '@/core/nlp/conversation' import Conversation, { DEFAULT_ACTIVE_CONTEXT } from '@/core/nlp/conversation'
export const DEFAULT_NLU_RESULT = { export const DEFAULT_NLU_RESULT = {
utterance: '', utterance: '',
@ -279,14 +279,15 @@ export default class NLU {
if (processedData.nextAction) { if (processedData.nextAction) {
this.conversation.cleanActiveContext() this.conversation.cleanActiveContext()
this.conversation.activeContext = { this.conversation.activeContext = {
...DEFAULT_ACTIVE_CONTEXT,
lang: BRAIN.lang, lang: BRAIN.lang,
slots: {}, slots: {},
isInActionLoop: !!processedData.nextAction.loop, isInActionLoop: !!processedData.nextAction.loop,
originalUtterance: processedData.utterance, originalUtterance: processedData.utterance ?? '',
skillConfigPath: processedData.skillConfigPath, skillConfigPath: processedData.skillConfigPath || '',
actionName: processedData.action.next_action, actionName: processedData.action?.next_action || '',
domain: processedData.classification.domain, domain: processedData.classification?.domain || '',
intent: `${processedData.classification.skill}.${processedData.action.next_action}`, intent: `${processedData.classification?.skill}.${processedData.action?.next_action}`,
entities: [] entities: []
} }
} }
@ -297,7 +298,7 @@ export default class NLU {
return resolve({ return resolve({
processingTime, // In ms, total time processingTime, // In ms, total time
...processedData, ...processedData,
nluProcessingTime: processingTime - processedData?.executionTime // In ms, NLU processing time only nluProcessingTime: processingTime - (processedData?.executionTime || 0) // In ms, NLU processing time only
}) })
} catch (e) { } catch (e) {
// TODO: TS refactor; verify how this works with the new error handling // TODO: TS refactor; verify how this works with the new error handling