From dcf50977505c1717633777f5d98064f0357cfd41 Mon Sep 17 00:00:00 2001 From: Mohamed Marrouchi Date: Mon, 9 Dec 2024 14:16:08 +0100 Subject: [PATCH] fix: rename nlp to nlu namespace --- api/src/channel/lib/EventWrapper.ts | 14 +++++--------- api/src/chat/schemas/types/context.ts | 4 ++-- api/src/chat/services/block.service.ts | 4 ++-- .../helpers/core-nlu/__test__/index.mock.ts | 4 ++-- .../extensions/helpers/core-nlu/index.helper.ts | 8 ++++---- api/src/extensions/helpers/llm-nlu/index.helper.ts | 8 ++++---- api/src/helper/lib/base-nlp-helper.ts | 6 +++--- api/src/helper/types.ts | 2 +- api/src/utils/test/mocks/nlp.ts | 4 ++-- 9 files changed, 25 insertions(+), 29 deletions(-) diff --git a/api/src/channel/lib/EventWrapper.ts b/api/src/channel/lib/EventWrapper.ts index 5cb2c1f6..8af15595 100644 --- a/api/src/channel/lib/EventWrapper.ts +++ b/api/src/channel/lib/EventWrapper.ts @@ -17,25 +17,21 @@ import { StdIncomingMessage, } from '@/chat/schemas/types/message'; import { Payload } from '@/chat/schemas/types/quick-reply'; -import { Nlp } from '@/helper/types'; +import { NLU } from '@/helper/types'; import ChannelHandler from './Handler'; export interface ChannelEvent {} // eslint-disable-next-line prettier/prettier -export default abstract class EventWrapper< - A, - E, - C extends ChannelHandler = ChannelHandler, -> { +export default abstract class EventWrapper { _adapter: A = {} as A; _handler: C; _profile!: Subscriber; - _nlp!: Nlp.ParseEntities; + _nlp!: NLU.ParseEntities; /** * Constructor : Class used to wrap any channel's event in order @@ -138,7 +134,7 @@ export default abstract class EventWrapper< * * @returns The parsed NLP entities, or null if not available. */ - getNLP(): Nlp.ParseEntities | null { + getNLP(): NLU.ParseEntities | null { return this._nlp; } @@ -147,7 +143,7 @@ export default abstract class EventWrapper< * * @param nlp - NLP parse results */ - setNLP(nlp: Nlp.ParseEntities) { + setNLP(nlp: NLU.ParseEntities) { this._nlp = nlp; } diff --git a/api/src/chat/schemas/types/context.ts b/api/src/chat/schemas/types/context.ts index cae1ccf6..73514097 100644 --- a/api/src/chat/schemas/types/context.ts +++ b/api/src/chat/schemas/types/context.ts @@ -7,7 +7,7 @@ */ import { ChannelName } from '@/channel/types'; -import { Nlp } from '@/helper/types'; +import { NLU } from '@/helper/types'; import { Subscriber } from '../subscriber.schema'; @@ -17,7 +17,7 @@ export interface Context { channel?: ChannelName; text?: string; payload?: Payload | string; - nlp?: Nlp.ParseEntities | null; + nlp?: NLU.ParseEntities | null; vars: { [key: string]: any }; user_location: { address?: Record; diff --git a/api/src/chat/services/block.service.ts b/api/src/chat/services/block.service.ts index 5251c932..e3dd3eaa 100644 --- a/api/src/chat/services/block.service.ts +++ b/api/src/chat/services/block.service.ts @@ -13,7 +13,7 @@ import { AttachmentService } from '@/attachment/services/attachment.service'; import EventWrapper from '@/channel/lib/EventWrapper'; import { ContentService } from '@/cms/services/content.service'; import { CONSOLE_CHANNEL_NAME } from '@/extensions/channels/console/settings'; -import { Nlp } from '@/helper/types'; +import { NLU } from '@/helper/types'; import { I18nService } from '@/i18n/services/i18n.service'; import { LanguageService } from '@/i18n/services/language.service'; import { LoggerService } from '@/logger/logger.service'; @@ -254,7 +254,7 @@ export class BlockService extends BaseService { * @returns The NLP patterns that matches */ matchNLP( - nlp: Nlp.ParseEntities, + nlp: NLU.ParseEntities, block: Block | BlockFull, ): NlpPattern[] | undefined { // No nlp entities to check against diff --git a/api/src/extensions/helpers/core-nlu/__test__/index.mock.ts b/api/src/extensions/helpers/core-nlu/__test__/index.mock.ts index 617710c3..c63e9cf3 100644 --- a/api/src/extensions/helpers/core-nlu/__test__/index.mock.ts +++ b/api/src/extensions/helpers/core-nlu/__test__/index.mock.ts @@ -6,7 +6,7 @@ * 2. All derivative works must include clear attribution to the original creator and software, Hexastack and Hexabot, in a prominent location (e.g., in the software's "About" section, documentation, and README file). */ -import { Nlp } from '@/helper/types'; +import { NLU } from '@/helper/types'; import { NlpParseResultType, RasaNlu } from '../types'; @@ -100,7 +100,7 @@ export const nlpParseResult: NlpParseResultType = { text: 'Hello Joe', }; -export const nlpBestGuess: Nlp.ParseEntities = { +export const nlpBestGuess: NLU.ParseEntities = { entities: [ { start: 5, diff --git a/api/src/extensions/helpers/core-nlu/index.helper.ts b/api/src/extensions/helpers/core-nlu/index.helper.ts index 6a2ebd39..a702475d 100644 --- a/api/src/extensions/helpers/core-nlu/index.helper.ts +++ b/api/src/extensions/helpers/core-nlu/index.helper.ts @@ -11,7 +11,7 @@ import { Injectable } from '@nestjs/common'; import { HelperService } from '@/helper/helper.service'; import BaseNlpHelper from '@/helper/lib/base-nlp-helper'; -import { Nlp } from '@/helper/types'; +import { NLU } from '@/helper/types'; import { LanguageService } from '@/i18n/services/language.service'; import { LoggerService } from '@/logger/logger.service'; import { NlpEntity, NlpEntityFull } from '@/nlp/schemas/nlp-entity.schema'; @@ -191,10 +191,10 @@ export default class CoreNluHelper extends BaseNlpHelper< async filterEntitiesByConfidence( nlp: NlpParseResultType, threshold: boolean, - ): Promise { + ): Promise { try { let minConfidence = 0; - const guess: Nlp.ParseEntities = { + const guess: NLU.ParseEntities = { entities: nlp.entities.slice(), }; if (threshold) { @@ -255,7 +255,7 @@ export default class CoreNluHelper extends BaseNlpHelper< text: string, threshold: boolean, project: string = 'current', - ): Promise { + ): Promise { try { const settings = await this.getSettings(); const { data: nlp } = diff --git a/api/src/extensions/helpers/llm-nlu/index.helper.ts b/api/src/extensions/helpers/llm-nlu/index.helper.ts index 25fdcdb1..814f24cf 100644 --- a/api/src/extensions/helpers/llm-nlu/index.helper.ts +++ b/api/src/extensions/helpers/llm-nlu/index.helper.ts @@ -12,7 +12,7 @@ import Handlebars from 'handlebars'; import { HelperService } from '@/helper/helper.service'; import BaseNlpHelper from '@/helper/lib/base-nlp-helper'; -import { LLM, Nlp } from '@/helper/types'; +import { LLM, NLU } from '@/helper/types'; import { LanguageService } from '@/i18n/services/language.service'; import { LoggerService } from '@/logger/logger.service'; import { NlpEntityFull } from '@/nlp/schemas/nlp-entity.schema'; @@ -103,7 +103,7 @@ export default class LlmNluHelper private findKeywordEntities( text: string, entity: NlpEntityFull, - ): Nlp.ParseEntity[] { + ): NLU.ParseEntity[] { return entity.values .flatMap(({ value, expressions }) => { const allValues = [value, ...expressions]; @@ -128,7 +128,7 @@ export default class LlmNluHelper .filter((v) => !!v); } - async predict(text: string): Promise { + async predict(text: string): Promise { const settings = await this.getSettings(); const helper = await this.helperService.getDefaultLlmHelper(); const defaultLanguage = await this.languageService.getDefaultLanguage(); @@ -143,7 +143,7 @@ export default class LlmNluHelper }, ); - const traits: Nlp.ParseEntity[] = [ + const traits: NLU.ParseEntity[] = [ { entity: 'language', value: language || defaultLanguage.code, diff --git a/api/src/helper/lib/base-nlp-helper.ts b/api/src/helper/lib/base-nlp-helper.ts index 90e17fb8..57c2f6cd 100644 --- a/api/src/helper/lib/base-nlp-helper.ts +++ b/api/src/helper/lib/base-nlp-helper.ts @@ -23,7 +23,7 @@ import { import { SettingService } from '@/setting/services/setting.service'; import { HelperService } from '../helper.service'; -import { HelperName, HelperType, Nlp } from '../types'; +import { HelperName, HelperType, NLU } from '../types'; import BaseHelper from './base-helper'; @@ -163,7 +163,7 @@ export default abstract class BaseNlpHelper< filterEntitiesByConfidence?( nlp: any, threshold: boolean, - ): Promise; + ): Promise; /** * Returns only the entities that have strong confidence (> than the threshold), can return an empty result @@ -178,5 +178,5 @@ export default abstract class BaseNlpHelper< text: string, threshold?: boolean, project?: string, - ): Promise; + ): Promise; } diff --git a/api/src/helper/types.ts b/api/src/helper/types.ts index 969120e9..055d18e0 100644 --- a/api/src/helper/types.ts +++ b/api/src/helper/types.ts @@ -13,7 +13,7 @@ import BaseHelper from './lib/base-helper'; import BaseLlmHelper from './lib/base-llm-helper'; import BaseNlpHelper from './lib/base-nlp-helper'; -export namespace Nlp { +export namespace NLU { export interface ParseEntity { entity: string; // Entity name value: string; // Value name diff --git a/api/src/utils/test/mocks/nlp.ts b/api/src/utils/test/mocks/nlp.ts index 5fb31634..04a6e0bd 100644 --- a/api/src/utils/test/mocks/nlp.ts +++ b/api/src/utils/test/mocks/nlp.ts @@ -6,9 +6,9 @@ * 2. All derivative works must include clear attribution to the original creator and software, Hexastack and Hexabot, in a prominent location (e.g., in the software's "About" section, documentation, and README file). */ -import { Nlp } from '@/helper/types'; +import { NLU } from '@/helper/types'; -export const nlpEntitiesGreeting: Nlp.ParseEntities = { +export const nlpEntitiesGreeting: NLU.ParseEntities = { entities: [ { entity: 'intent',