diff --git a/api/src/chat/services/block.service.ts b/api/src/chat/services/block.service.ts index 75373f1f..3c1308a0 100644 --- a/api/src/chat/services/block.service.ts +++ b/api/src/chat/services/block.service.ts @@ -16,7 +16,7 @@ import { CONSOLE_CHANNEL_NAME } from '@/extensions/channels/console/settings'; import { NLU } from '@/helper/types'; import { I18nService } from '@/i18n/services/i18n.service'; import { LanguageService } from '@/i18n/services/language.service'; -import { NlpCacheMapValues } from '@/nlp/schemas/types'; +import { NlpEntityFull } from '@/nlp/schemas/nlp-entity.schema'; import { NlpEntityService } from '@/nlp/services/nlp-entity.service'; import { PluginService } from '@/plugins/plugins.service'; import { PluginType } from '@/plugins/types'; @@ -403,7 +403,6 @@ export class BlockService extends BaseService< const matchedEntity: NLU.ParseEntity | undefined = nlp.entities.find( (e) => this.matchesEntityData(e, pattern, entityData!), ); - return this.computePatternScore( matchedEntity, pattern, @@ -434,11 +433,11 @@ export class BlockService extends BaseService< private matchesEntityData( e: NLU.ParseEntity, pattern: NlpPattern, - entityData: NlpCacheMapValues, + entityData: NlpEntityFull, ): boolean { return ( e.entity === pattern.entity && - entityData?.values.some((v) => v === e.value) && + entityData.values?.some((v) => v.value === e.value) && (pattern.match !== 'value' || e.value === pattern.value) ); } @@ -455,7 +454,7 @@ export class BlockService extends BaseService< private computePatternScore( entity: NLU.ParseEntity | undefined, pattern: NlpPattern, - entityData: NlpCacheMapValues, + entityData: NlpEntityFull, nlpPenaltyFactor: number, ): number { if (!entity || !entity.confidence) return 0; diff --git a/api/src/nlp/schemas/types.ts b/api/src/nlp/schemas/types.ts index 96b7dae4..6e87dee3 100644 --- a/api/src/nlp/schemas/types.ts +++ b/api/src/nlp/schemas/types.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 { NlpEntityStub } from './nlp-entity.schema'; +import { NlpEntityFull, NlpEntityStub } from './nlp-entity.schema'; import { NlpValueStub } from './nlp-value.schema'; export interface NlpSampleEntityValue { @@ -26,10 +26,4 @@ export enum NlpSampleState { inbox = 'inbox', } -export type NlpCacheMap = Map; - -export type NlpCacheMapValues = { - id: string; - weight: number; - values: string[]; -}; +export type NlpCacheMap = Map; diff --git a/api/src/utils/test/mocks/nlp.ts b/api/src/utils/test/mocks/nlp.ts index a88b3bbd..b5a08c02 100644 --- a/api/src/utils/test/mocks/nlp.ts +++ b/api/src/utils/test/mocks/nlp.ts @@ -63,17 +63,74 @@ export const mockNlpCacheMap: NlpCacheMap = new Map([ [ 'intent', { - id: '67e3e41eff551ca5be70559c', + id: '1', weight: 1, - values: ['greeting', 'affirmation'], + name: 'intent', + values: [ + { + id: '11', + value: 'greeting', + createdAt: new Date(), + updatedAt: new Date(), + doc: '', + entity: '1', + builtin: false, + metadata: {}, + expressions: [], + }, + { + id: '12', + value: 'affirmation', + createdAt: new Date(), + updatedAt: new Date(), + doc: '', + entity: '1', + builtin: false, + metadata: {}, + expressions: [], + }, + ], + lookups: ['trait'], + builtin: false, + createdAt: new Date(), + updatedAt: new Date(), }, ], [ 'firstname', + { - id: '67e3e41eff551ca5be70559d', + id: '2', weight: 1, - values: ['jhon', 'doe'], + name: 'firstname', + values: [ + { + id: '21', + value: 'jhon', + createdAt: new Date(), + updatedAt: new Date(), + doc: '', + entity: '2', + builtin: false, + metadata: {}, + expressions: [], + }, + { + id: '22', + value: 'doe', + createdAt: new Date(), + updatedAt: new Date(), + doc: '', + entity: '2', + builtin: false, + metadata: {}, + expressions: [], + }, + ], + lookups: ['trait'], + builtin: false, + createdAt: new Date(), + updatedAt: new Date(), }, ], ]);