From 0ce78946286f68d07cd5bb7bff3ea1fbd31bf176 Mon Sep 17 00:00:00 2001 From: MohamedAliBouhaouala Date: Thu, 24 Apr 2025 19:17:38 +0100 Subject: [PATCH] fix: enforce typing --- api/src/chat/services/block.service.spec.ts | 4 ++-- api/src/chat/services/block.service.ts | 7 ++++++- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/api/src/chat/services/block.service.spec.ts b/api/src/chat/services/block.service.spec.ts index 100265cd..2debdb94 100644 --- a/api/src/chat/services/block.service.spec.ts +++ b/api/src/chat/services/block.service.spec.ts @@ -363,7 +363,7 @@ describe('BlockService', () => { }); describe('matchBestNLP', () => { - const nlpPenaltyFactor = 2; + const nlpPenaltyFactor = 0.95; it('should return the block with the highest NLP score', async () => { jest .spyOn(nlpEntityService, 'getNlpMap') @@ -417,7 +417,7 @@ describe('BlockService', () => { // Restore the spy after the test calculateBlockScoreSpy.mockRestore(); // Assert that the block with the highest NLP score is selected - expect(bestBlock).toEqual(mockModifiedNlpBlock); + expect(bestBlock).toEqual(mockNlpBlock); }); it('should return undefined if no blocks match or the list is empty', async () => { diff --git a/api/src/chat/services/block.service.ts b/api/src/chat/services/block.service.ts index d6d9a52a..d15b0327 100644 --- a/api/src/chat/services/block.service.ts +++ b/api/src/chat/services/block.service.ts @@ -215,7 +215,12 @@ export class BlockService extends BaseService< ); // Retrieve Nlu Penalty Factor from global settings - const nluPenaltyFactor = await this.getDefaultNluPenaltyFactor(); + const nluPenaltyFactor: number = + await this.getDefaultNluPenaltyFactor(); + + if (nluPenaltyFactor < 0 || nluPenaltyFactor > 1) { + throw new Error('Penalty Factor must be between 0 and 1.'); + } // Proceed with matching the best NLP block if (matchesWithPatterns.length > 0) {