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(
|
||||
|
||||
@@ -123,7 +123,7 @@
|
||||
"video_error": "Video not found",
|
||||
"missing_fields_error": "Please make sure that all required fields are filled",
|
||||
"weight_required_error": "Weight is required or invalid",
|
||||
"weight_positive_integer_error": "Weight must be a positive integer"
|
||||
"weight_positive_number_error": "Weight must be a positive number"
|
||||
},
|
||||
"menu": {
|
||||
"terms": "Terms of Use",
|
||||
|
||||
@@ -122,7 +122,7 @@
|
||||
"audio_error": "Audio introuvable",
|
||||
"video_error": "Vidéo introuvable",
|
||||
"missing_fields_error": "Veuillez vous assurer que tous les champs sont remplis correctement",
|
||||
"weight_positive_integer_error": "Le poids doit être un nombre entier positif",
|
||||
"weight_positive_number_error": "Le poids doit être un nombre positif",
|
||||
"weight_required_error": "Le poids est requis ou bien invalide"
|
||||
},
|
||||
"menu": {
|
||||
|
||||
@@ -141,18 +141,18 @@ export const NlpEntityVarForm: FC<ComponentFormProps<INlpEntity>> = ({
|
||||
valueAsNumber: true,
|
||||
required: t("message.weight_required_error"),
|
||||
min: {
|
||||
value: 1,
|
||||
message: t("message.weight_positive_integer_error"),
|
||||
value: 0.01,
|
||||
message: t("message.weight_positive_number_error"),
|
||||
},
|
||||
validate: (value) =>
|
||||
value && Number.isInteger(value) && value! > 0
|
||||
value && value! > 0
|
||||
? true
|
||||
: t("message.weight_positive_integer_error"),
|
||||
: t("message.weight_positive_number_error"),
|
||||
})}
|
||||
type="number"
|
||||
inputProps={{
|
||||
min: 1,
|
||||
step: 1,
|
||||
min: 0.01,
|
||||
step: 0.01,
|
||||
inputMode: "numeric",
|
||||
pattern: "[1-9][0-9]*",
|
||||
}}
|
||||
|
||||
Reference in New Issue
Block a user