Merge pull request #840 from Hexastack/feat/add-doc-field-nlp-values

feat: add description attribute for nlu values
This commit is contained in:
Med Marrouchi 2025-03-24 10:19:24 +01:00 committed by GitHub
commit 13cf35b828
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
9 changed files with 54 additions and 9 deletions

View File

@ -1,5 +1,5 @@
/* /*
* Copyright © 2024 Hexastack. All rights reserved. * Copyright © 2025 Hexastack. All rights reserved.
* *
* Licensed under the GNU Affero General Public License v3.0 (AGPLv3) with the following additional terms: * Licensed under the GNU Affero General Public License v3.0 (AGPLv3) with the following additional terms:
* 1. The name "Hexabot" is a trademark of Hexastack. You may not use this name in derivative works without express written permission. * 1. The name "Hexabot" is a trademark of Hexastack. You may not use this name in derivative works without express written permission.
@ -379,6 +379,7 @@ describe('NlpSampleController', () => {
expressions: [], expressions: [],
builtin: false, builtin: false,
entity: priceValueEntity!.id, entity: priceValueEntity!.id,
doc: '',
}; };
const textSample = { const textSample = {
text: 'How much does a BMW cost?', text: 'How much does a BMW cost?',

View File

@ -1,5 +1,5 @@
/* /*
* Copyright © 2024 Hexastack. All rights reserved. * Copyright © 2025 Hexastack. All rights reserved.
* *
* Licensed under the GNU Affero General Public License v3.0 (AGPLv3) with the following additional terms: * Licensed under the GNU Affero General Public License v3.0 (AGPLv3) with the following additional terms:
* 1. The name "Hexabot" is a trademark of Hexastack. You may not use this name in derivative works without express written permission. * 1. The name "Hexabot" is a trademark of Hexastack. You may not use this name in derivative works without express written permission.
@ -157,6 +157,7 @@ describe('NlpValueController', () => {
expressions: ['synonym1', 'synonym2'], expressions: ['synonym1', 'synonym2'],
metadata: { firstkey: 'firstvalue', secondKey: 1995 }, metadata: { firstkey: 'firstvalue', secondKey: 1995 },
builtin: false, builtin: false,
doc: '',
}; };
const result = await nlpValueController.create(value); const result = await nlpValueController.create(value);
expect(result).toEqualPayload(value); expect(result).toEqualPayload(value);
@ -223,6 +224,7 @@ describe('NlpValueController', () => {
value: 'updated', value: 'updated',
expressions: [], expressions: [],
builtin: true, builtin: true,
doc: '',
}; };
const result = await nlpValueController.updateOne( const result = await nlpValueController.updateOne(
positiveValue!.id, positiveValue!.id,
@ -241,6 +243,7 @@ describe('NlpValueController', () => {
value: 'updated', value: 'updated',
expressions: [], expressions: [],
builtin: true, builtin: true,
doc: '',
}), }),
).rejects.toThrow(getUpdateOneError(NlpValue.name, jhonNlpValue!.id)); ).rejects.toThrow(getUpdateOneError(NlpValue.name, jhonNlpValue!.id));
}); });

View File

@ -93,7 +93,9 @@ export class NlpValueController extends BaseController<
@Get('count') @Get('count')
async filterCount( async filterCount(
@Query( @Query(
new SearchFilterPipe<NlpValue>({ allowedFields: ['entity', 'value'] }), new SearchFilterPipe<NlpValue>({
allowedFields: ['entity', 'value', 'doc'],
}),
) )
filters?: TFilterQuery<NlpValue>, filters?: TFilterQuery<NlpValue>,
) { ) {
@ -142,7 +144,7 @@ export class NlpValueController extends BaseController<
@Query(PopulatePipe) populate: string[], @Query(PopulatePipe) populate: string[],
@Query( @Query(
new SearchFilterPipe<NlpValue>({ new SearchFilterPipe<NlpValue>({
allowedFields: ['entity', 'value'], allowedFields: ['entity', 'value', 'doc'],
}), }),
) )
filters: TFilterQuery<NlpValue>, filters: TFilterQuery<NlpValue>,

View File

@ -1,5 +1,5 @@
/* /*
* Copyright © 2024 Hexastack. All rights reserved. * Copyright © 2025 Hexastack. All rights reserved.
* *
* Licensed under the GNU Affero General Public License v3.0 (AGPLv3) with the following additional terms: * Licensed under the GNU Affero General Public License v3.0 (AGPLv3) with the following additional terms:
* 1. The name "Hexabot" is a trademark of Hexastack. You may not use this name in derivative works without express written permission. * 1. The name "Hexabot" is a trademark of Hexastack. You may not use this name in derivative works without express written permission.
@ -39,6 +39,11 @@ export class NlpValueCreateDto {
@IsObject() @IsObject()
metadata?: Record<string, any>; metadata?: Record<string, any>;
@ApiPropertyOptional({ description: 'Nlp Value Description', type: String })
@IsString()
@IsOptional()
doc?: string;
@ApiPropertyOptional({ description: 'Nlp value is builtin', type: Boolean }) @ApiPropertyOptional({ description: 'Nlp value is builtin', type: Boolean })
@IsOptional() @IsOptional()
@IsBoolean() @IsBoolean()
@ -77,6 +82,11 @@ export class NlpValueUpdateDto {
@IsObjectId({ message: 'Entity must be a valid ObjectId' }) @IsObjectId({ message: 'Entity must be a valid ObjectId' })
entity?: string | null; entity?: string | null;
@ApiPropertyOptional({ description: 'Nlp Value Description', type: String })
@IsString()
@IsOptional()
doc?: string;
@ApiPropertyOptional({ description: 'Nlp value is builtin', type: Boolean }) @ApiPropertyOptional({ description: 'Nlp value is builtin', type: Boolean })
@IsOptional() @IsOptional()
@IsBoolean() @IsBoolean()

View File

@ -1,5 +1,5 @@
/* /*
* Copyright © 2024 Hexastack. All rights reserved. * Copyright © 2025 Hexastack. All rights reserved.
* *
* Licensed under the GNU Affero General Public License v3.0 (AGPLv3) with the following additional terms: * Licensed under the GNU Affero General Public License v3.0 (AGPLv3) with the following additional terms:
* 1. The name "Hexabot" is a trademark of Hexastack. You may not use this name in derivative works without express written permission. * 1. The name "Hexabot" is a trademark of Hexastack. You may not use this name in derivative works without express written permission.
@ -46,6 +46,12 @@ export class NlpValueStub extends BaseSchema {
@Prop({ type: JSON, default: {} }) @Prop({ type: JSON, default: {} })
metadata: Record<string, any>; metadata: Record<string, any>;
/**
* Description of the entity's value purpose.
*/
@Prop({ type: String, default: '' })
doc?: string;
/** /**
* Either or not this value a built-in (either fixtures or shipped along with the 3rd party ai). * Either or not this value a built-in (either fixtures or shipped along with the 3rd party ai).
*/ */

View File

@ -1,5 +1,5 @@
/* /*
* Copyright © 2024 Hexastack. All rights reserved. * Copyright © 2025 Hexastack. All rights reserved.
* *
* Licensed under the GNU Affero General Public License v3.0 (AGPLv3) with the following additional terms: * Licensed under the GNU Affero General Public License v3.0 (AGPLv3) with the following additional terms:
* 1. The name "Hexabot" is a trademark of Hexastack. You may not use this name in derivative works without express written permission. * 1. The name "Hexabot" is a trademark of Hexastack. You may not use this name in derivative works without express written permission.
@ -19,30 +19,35 @@ export const nlpValueFixtures: NlpValueCreateDto[] = [
value: 'positive', value: 'positive',
expressions: [], expressions: [],
builtin: true, builtin: true,
doc: '',
}, },
{ {
entity: '0', entity: '0',
value: 'negative', value: 'negative',
expressions: [], expressions: [],
builtin: true, builtin: true,
doc: '',
}, },
{ {
entity: '1', entity: '1',
value: 'jhon', value: 'jhon',
expressions: ['john', 'joohn', 'jhonny'], expressions: ['john', 'joohn', 'jhonny'],
builtin: true, builtin: true,
doc: '',
}, },
{ {
entity: '0', entity: '0',
value: 'greeting', value: 'greeting',
expressions: ['heello', 'Hello', 'hi', 'heyy'], expressions: ['heello', 'Hello', 'hi', 'heyy'],
builtin: true, builtin: true,
doc: '',
}, },
{ {
entity: '0', entity: '0',
value: 'goodbye', value: 'goodbye',
expressions: ['bye', 'bye bye'], expressions: ['bye', 'bye bye'],
builtin: true, builtin: true,
doc: '',
}, },
]; ];

View File

@ -55,7 +55,7 @@ export const NlpValues = ({ entityId }: { entityId: string }) => {
const canHaveSynonyms = nlpEntity?.lookups?.[0] === NlpLookups.keywords; const canHaveSynonyms = nlpEntity?.lookups?.[0] === NlpLookups.keywords;
const { onSearch, searchPayload } = useSearch<INlpValue>({ const { onSearch, searchPayload } = useSearch<INlpValue>({
$eq: [{ entity: entityId }], $eq: [{ entity: entityId }],
$iLike: ["value"], $or: ["doc", "value"]
}); });
const { dataGridProps } = useFind( const { dataGridProps } = useFind(
{ entity: EntityType.NLP_VALUE }, { entity: EntityType.NLP_VALUE },
@ -125,6 +125,14 @@ export const NlpValues = ({ entityId }: { entityId: string }) => {
disableColumnMenu: true, disableColumnMenu: true,
renderHeader, renderHeader,
}, },
{
flex: 3,
field: "doc",
headerName: t("label.doc"),
sortable: true,
disableColumnMenu: true,
renderHeader,
},
...(shouldIncludeSynonyms ? [synonymsColumn] : []), ...(shouldIncludeSynonyms ? [synonymsColumn] : []),
{ {
maxWidth: 140, maxWidth: 140,

View File

@ -61,6 +61,7 @@ export const NlpValueForm: FC<
>({ >({
defaultValues: { defaultValues: {
value: data?.value || "", value: data?.value || "",
doc: data?.doc || "",
expressions: data?.expressions || [], expressions: data?.expressions || [],
}, },
}); });
@ -84,6 +85,7 @@ export const NlpValueForm: FC<
reset({ reset({
value: data.value, value: data.value,
expressions: data.expressions, expressions: data.expressions,
doc: data.doc,
}); });
} else { } else {
reset(); reset();
@ -102,6 +104,13 @@ export const NlpValueForm: FC<
{...register("value", validationRules.value)} {...register("value", validationRules.value)}
/> />
</ContentItem> </ContentItem>
<ContentItem>
<Input
label={t("label.doc")}
{...register("doc")}
multiline={true}
/>
</ContentItem>
{canHaveSynonyms ? ( {canHaveSynonyms ? (
<ContentItem> <ContentItem>

View File

@ -1,5 +1,5 @@
/* /*
* Copyright © 2024 Hexastack. All rights reserved. * Copyright © 2025 Hexastack. All rights reserved.
* *
* Licensed under the GNU Affero General Public License v3.0 (AGPLv3) with the following additional terms: * Licensed under the GNU Affero General Public License v3.0 (AGPLv3) with the following additional terms:
* 1. The name "Hexabot" is a trademark of Hexastack. You may not use this name in derivative works without express written permission. * 1. The name "Hexabot" is a trademark of Hexastack. You may not use this name in derivative works without express written permission.
@ -15,6 +15,7 @@ export interface INlpValueAttributes {
entity: string; entity: string;
foreign_id?: string; foreign_id?: string;
value: string; value: string;
doc?: string;
expressions?: string[]; expressions?: string[];
metadata?: Record<string, any>; metadata?: Record<string, any>;
builtin?: boolean; builtin?: boolean;