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

refactor(server): NLP.js process raw type

This commit is contained in:
louistiti 2023-04-02 18:00:10 +08:00
parent 44882129a7
commit a6011e3cc6
No known key found for this signature in database
GPG Key ID: 92CD6A2E497E1669
5 changed files with 41 additions and 8 deletions

View File

@ -1 +0,0 @@
// TODO

View File

@ -1 +0,0 @@
// TODO

View File

@ -4,7 +4,7 @@ import { spawn } from 'node:child_process'
import kill from 'tree-kill'
import type { Language, ShortLanguageCode } from '@/types'
import type { NLPAction, NLPDomain, NLPSkill, NLPUtterance, NLUResult } from '@/core/nlp/types'
import type { NLPAction, NLPDomain, NLPJSProcessResult, NLPSkill, NLPUtterance, NLUResult } from '@/core/nlp/types'
import { langs } from '@@/core/langs.json'
import { TCP_SERVER_BIN_PATH } from '@/constants'
import { TCP_CLIENT, BRAIN, SOCKET_SERVER, MODEL_LOADER, NER } from '@/core'
@ -117,7 +117,7 @@ export default class NLU {
}
}
const result = await MODEL_LOADER.mainNLPContainer.process(utterance)
const result: NLPJSProcessResult = await MODEL_LOADER.mainNLPContainer.process(utterance)
const { locale, answers, classifications } = result
let { score, intent, domain } = result
@ -149,8 +149,8 @@ export default class NLU {
answers, // For dialog action type
classification: {
domain,
skill: skillName,
action: actionName,
skill: skillName || '',
action: actionName || '',
confidence: score
}
}

View File

@ -1 +0,0 @@
// TODO

View File

@ -1,3 +1,5 @@
import type { ShortLanguageCode } from '@/types'
/**
* NLP types
*/
@ -7,6 +9,39 @@ export type NLPSkill = string
export type NLPAction = string
export type NLPUtterance = string
export interface NLPJSProcessResult {
locale: ShortLanguageCode
utterance: NLPUtterance
settings: unknown
languageGuessed: boolean
localeIso2: ShortLanguageCode
language: string
explanation: []
classifications: {
intent: string
score: number
}[]
intent: string // E.g. "greeting.run"
score: number
domain: NLPDomain
sourceEntities: unknown[]
entities: NEREntity[]
answers: {
answer: string
}[]
answer: string | undefined
actions: NLPAction[]
sentiment: {
score: number
numWords: number
numHits: number
average: number
type: string
locale: ShortLanguageCode
vote: string
}
}
/**
* NLU types
*/
@ -231,6 +266,7 @@ export interface CustomEnumEntity extends CustomEntity<'enum'> {
resolution: {
value: string
}
alias?: string // E.g. "location:country_0"; "location:country_1"
}
type GlobalEntity = CustomEnumEntity
export interface CustomRegexEntity extends CustomEntity<'regex'> {
@ -247,7 +283,7 @@ interface CustomTrimEntity extends CustomEntity<'trim'> {
}
/**
* spaCy entity types
* spaCy's entity types
*/
interface SpacyEntity<T> extends CustomEnumEntity {