mirror of
https://github.com/hexastack/hexabot
synced 2025-06-26 18:27:28 +00:00
feat: set nlpEntity weights type to float
This commit is contained in:
committed by
Mohamed Marrouchi
parent
003c6924f8
commit
5dcd36be98
@@ -384,8 +384,6 @@ export class BlockService extends BaseService<
|
||||
*
|
||||
* @param patterns - The NLP patterns associated with the block.
|
||||
* @param nlp - The parsed NLP entities from the user input.
|
||||
* @param nlpCacheMap - A cache to reuse fetched entity metadata (e.g., weights and valid values).
|
||||
* @param nlpPenaltyFactor - A multiplier applied to scores when the pattern match type is 'entity'.
|
||||
* @returns A numeric score representing how well the block matches the given NLP context.
|
||||
*/
|
||||
async calculateBlockScore(
|
||||
|
||||
@@ -311,7 +311,7 @@ describe('NlpEntityController', () => {
|
||||
doc: '',
|
||||
lookups: ['trait'],
|
||||
builtin: false,
|
||||
weight: 4,
|
||||
weight: 8,
|
||||
};
|
||||
const originalEntity: NlpEntity | null = await nlpEntityService.findOne(
|
||||
buitInEntityId!,
|
||||
|
||||
@@ -11,8 +11,8 @@ import {
|
||||
IsArray,
|
||||
IsBoolean,
|
||||
IsIn,
|
||||
IsInt,
|
||||
IsNotEmpty,
|
||||
IsNumber,
|
||||
IsOptional,
|
||||
IsString,
|
||||
Matches,
|
||||
@@ -53,11 +53,10 @@ export class NlpEntityCreateDto {
|
||||
@ApiPropertyOptional({
|
||||
description: 'Nlp entity associated weight for next block triggering',
|
||||
type: Number,
|
||||
minimum: 1,
|
||||
})
|
||||
@IsOptional()
|
||||
@Min(1, { message: 'Weight must be a positive integer' })
|
||||
@IsInt({ message: 'Weight must be an integer' })
|
||||
@Min(0.01, { message: 'Weight must be positive' })
|
||||
@IsNumber()
|
||||
weight?: number;
|
||||
}
|
||||
|
||||
|
||||
@@ -170,28 +170,12 @@ describe('nlpEntityService', () => {
|
||||
expect(createdEntity.weight).toBe(1);
|
||||
});
|
||||
|
||||
it('should throw an error if weight is less than 1', async () => {
|
||||
const invalidWeight = 0;
|
||||
|
||||
await expect(
|
||||
nlpEntityService.updateWeight(createdEntity.id, invalidWeight),
|
||||
).rejects.toThrow('Weight must be a positive integer');
|
||||
});
|
||||
|
||||
it('should throw an error if weight is a decimal', async () => {
|
||||
const invalidWeight = 2.5;
|
||||
|
||||
await expect(
|
||||
nlpEntityService.updateWeight(createdEntity.id, invalidWeight),
|
||||
).rejects.toThrow('Weight must be a positive integer');
|
||||
});
|
||||
|
||||
it('should throw an error if weight is negative', async () => {
|
||||
const invalidWeight = -3;
|
||||
|
||||
await expect(
|
||||
nlpEntityService.updateWeight(createdEntity.id, invalidWeight),
|
||||
).rejects.toThrow('Weight must be a positive integer');
|
||||
).rejects.toThrow('Weight must be a positive number');
|
||||
});
|
||||
|
||||
afterEach(async () => {
|
||||
|
||||
@@ -58,13 +58,13 @@ export class NlpEntityService extends BaseService<
|
||||
* This method is part of the NLP-based blocks prioritization strategy.
|
||||
* The weight influences the scoring of blocks when multiple blocks match a user's input.
|
||||
* @param id - The unique identifier of the entity to update.
|
||||
* @param updatedWeight - The new weight to assign. Must be a positive integer.
|
||||
* @throws Error if the weight is not a positive integer.
|
||||
* @param updatedWeight - The new weight to assign. Must be a positive number.
|
||||
* @throws Error if the weight is not a positive number.
|
||||
* @returns A promise that resolves to the updated entity.
|
||||
*/
|
||||
async updateWeight(id: string, updatedWeight: number): Promise<NlpEntity> {
|
||||
if (!Number.isInteger(updatedWeight) || updatedWeight < 1) {
|
||||
throw new Error('Weight must be a positive integer');
|
||||
if (updatedWeight < 0) {
|
||||
throw new Error('Weight must be a positive number');
|
||||
}
|
||||
|
||||
return await this.repository.updateOne(
|
||||
|
||||
Reference in New Issue
Block a user