mirror of
https://github.com/hexastack/hexabot
synced 2025-06-26 18:27:28 +00:00
fix: minor fixes
This commit is contained in:
parent
41de535a7c
commit
a054ee542e
@ -416,7 +416,7 @@ describe('BlockService', () => {
|
||||
blockService,
|
||||
'calculateNluPatternMatchScore',
|
||||
);
|
||||
const bestBlock = await blockService.matchBestNLP(
|
||||
const bestBlock = blockService.matchBestNLP(
|
||||
blocks,
|
||||
mockNlpGreetingNameEntities,
|
||||
);
|
||||
@ -458,7 +458,7 @@ describe('BlockService', () => {
|
||||
blockService,
|
||||
'calculateNluPatternMatchScore',
|
||||
);
|
||||
const bestBlock = await blockService.matchBestNLP(blocks, nlp);
|
||||
const bestBlock = blockService.matchBestNLP(blocks, nlp);
|
||||
|
||||
// Ensure calculateBlockScore was called at least once for each block
|
||||
expect(calculateBlockScoreSpy).toHaveBeenCalledTimes(3); // Called for each block
|
||||
@ -476,7 +476,7 @@ describe('BlockService', () => {
|
||||
blockGetStarted,
|
||||
];
|
||||
|
||||
const bestBlock = await blockService.matchBestNLP(
|
||||
const bestBlock = blockService.matchBestNLP(
|
||||
blocks,
|
||||
mockNlpGreetingNameEntities,
|
||||
);
|
||||
|
@ -181,7 +181,7 @@ export class BlockService extends BaseService<
|
||||
const scoredEntities =
|
||||
await this.nlpService.computePredictionScore(nlp);
|
||||
|
||||
block = await this.matchBestNLP(filteredBlocks, scoredEntities);
|
||||
block = this.matchBestNLP(filteredBlocks, scoredEntities);
|
||||
}
|
||||
}
|
||||
|
||||
@ -344,10 +344,10 @@ export class BlockService extends BaseService<
|
||||
* @returns A promise that resolves to the block with the highest NLP match score,
|
||||
* or `undefined` if no suitable match is found.
|
||||
*/
|
||||
async matchBestNLP<B extends BlockStub>(
|
||||
matchBestNLP<B extends BlockStub>(
|
||||
blocks: B[],
|
||||
scoredEntities: NLU.ScoredEntities,
|
||||
): Promise<B | undefined> {
|
||||
): B | undefined {
|
||||
const bestMatch = blocks.reduce(
|
||||
(bestMatch, block) => {
|
||||
const matchedPatterns = this.getMatchingNluPatterns(
|
||||
@ -405,17 +405,9 @@ export class BlockService extends BaseService<
|
||||
const matchedEntity: NLU.ScoredEntity | undefined =
|
||||
prediction.entities.find((e) => this.matchesNluEntity(e, pattern));
|
||||
|
||||
if (!matchedEntity) {
|
||||
throw new Error(
|
||||
'Unable to compute the NLU match score : pattern / entity mismatch',
|
||||
);
|
||||
}
|
||||
|
||||
const patternScore = this.computePatternScore(
|
||||
matchedEntity,
|
||||
pattern,
|
||||
penaltyFactor,
|
||||
);
|
||||
const patternScore = matchedEntity
|
||||
? this.computePatternScore(matchedEntity, pattern, penaltyFactor)
|
||||
: 0;
|
||||
|
||||
return score + patternScore;
|
||||
}, 0);
|
||||
|
Loading…
Reference in New Issue
Block a user