fix: rename nlp to nlu namespace

This commit is contained in:
Mohamed Marrouchi 2024-12-09 14:16:08 +01:00
parent f9caf0f458
commit dcf5097750
9 changed files with 25 additions and 29 deletions

View File

@ -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<A, E, C extends ChannelHandler = ChannelHandler> {
_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;
}

View File

@ -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<string, string>;

View File

@ -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<Block, BlockPopulate, BlockFull> {
* @returns The NLP patterns that matches
*/
matchNLP(
nlp: Nlp.ParseEntities,
nlp: NLU.ParseEntities,
block: Block | BlockFull,
): NlpPattern[] | undefined {
// No nlp entities to check against

View File

@ -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,

View File

@ -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<Nlp.ParseEntities> {
): Promise<NLU.ParseEntities> {
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<Nlp.ParseEntities> {
): Promise<NLU.ParseEntities> {
try {
const settings = await this.getSettings();
const { data: nlp } =

View File

@ -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<Nlp.ParseEntities> {
async predict(text: string): Promise<NLU.ParseEntities> {
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,

View File

@ -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<Nlp.ParseEntities>;
): Promise<NLU.ParseEntities>;
/**
* 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<Nlp.ParseEntities>;
): Promise<NLU.ParseEntities>;
}

View File

@ -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

View File

@ -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',