feat: refactor helpers (nlu)

This commit is contained in:
Mohamed Marrouchi
2024-10-21 15:09:59 +01:00
parent b2c32fe27d
commit b7eef89981
53 changed files with 901 additions and 731 deletions

View File

@@ -4,10 +4,12 @@
},
"label": {
"global_fallback": "Enable Global Fallback?",
"fallback_message": "Fallback Message"
"fallback_message": "Fallback Message",
"default_nlu_helper": "Default NLU Helper"
},
"help": {
"global_fallback": "Global fallback allows you to send custom messages when user entry does not match any of the block messages.",
"fallback_message": "If no fallback block is selected, then one of these messages will be sent."
"fallback_message": "If no fallback block is selected, then one of these messages will be sent.",
"default_nlu_helper": "The NLU helper is responsible for processing and understanding user inputs, including tasks like intent prediction, language detection, and entity recognition."
}
}

View File

@@ -1,13 +1,15 @@
{
"title": {
"chatbot_settings": "Chatbot"
"chatbot_settings": "Paramètres du Chatbot"
},
"label": {
"global_fallback": "Activer le message de secours global?",
"fallback_message": "Message de secours"
"global_fallback": "Activer la réponse de secours globale ?",
"fallback_message": "Message de secours",
"default_nlu_helper": "Utilitaire NLU par défaut"
},
"help": {
"global_fallback": "Le message de secours global vous permet d'envoyer des messages personnalisés lorsque le message de l'utilisateur ne déclenche aucun bloc de message.",
"fallback_message": "Si aucun bloc de secours n'est spécifié, alors de ces messages sera envoyé."
"global_fallback": "La réponse de secours globale vous permet d'envoyer des messages personnalisés lorsque l'entrée de l'utilisateur ne correspond à aucun des messages des blocs.",
"fallback_message": "Si aucun bloc de secours n'est sélectionné, l'un de ces messages sera envoyé.",
"default_nlu_helper": "Utilitaire du traitement et de la compréhension des entrées des utilisateurs, incluant des tâches telles que la prédiction d'intention, la détection de langue et la reconnaissance d'entités."
}
}

View File

@@ -11,7 +11,7 @@ import Autocomplete, {
AutocompleteProps,
AutocompleteValue,
} from "@mui/material/Autocomplete";
import { useState, useCallback, useMemo, useEffect, forwardRef } from "react";
import { forwardRef, useCallback, useEffect, useMemo, useState } from "react";
import { Input } from "@/app-components/inputs/Input";

View File

@@ -19,6 +19,7 @@ import { PasswordInput } from "@/app-components/inputs/PasswordInput";
import { useTranslate } from "@/hooks/useTranslate";
import { EntityType, Format } from "@/services/types";
import { IBlock } from "@/types/block.types";
import { IHelper } from "@/types/helper.types";
import { ISetting } from "@/types/setting.types";
import { MIME_TYPES } from "@/utils/attachment";
@@ -115,11 +116,29 @@ const SettingInput: React.FC<RenderSettingInputProps> = ({
format={Format.BASIC}
labelKey="name"
label={t("label.fallback_block")}
helperText={t("help.fallback_block")}
multiple={false}
onChange={(_e, selected, ..._) => onChange(selected?.id)}
{...rest}
/>
);
} else if (setting.label === "default_nlu_helper") {
const { onChange, ...rest } = field;
return (
<AutoCompleteEntitySelect<IHelper, "name", false>
searchFields={["name"]}
entity={EntityType.NLU_HELPER}
format={Format.BASIC}
labelKey="name"
idKey="name"
label={t("label.default_nlu_helper")}
helperText={t("help.default_nlu_helper")}
multiple={false}
onChange={(_e, selected, ..._) => onChange(selected?.name)}
{...rest}
/>
);
}
return (

View File

@@ -64,6 +64,8 @@ export const ROUTES = {
[EntityType.TRANSLATION]: "/translation",
[EntityType.ATTACHMENT]: "/attachment",
[EntityType.CHANNEL]: "/channel",
[EntityType.HELPER]: "/helper",
[EntityType.NLU_HELPER]: "/helper/nlu",
} as const;
export class ApiClient {

View File

@@ -284,6 +284,19 @@ export const ChannelEntity = new schema.Entity(EntityType.CHANNEL, undefined, {
idAttribute: ({ name }) => name,
});
export const HelperEntity = new schema.Entity(EntityType.HELPER, undefined, {
idAttribute: ({ name }) => name,
});
export const NluHelperEntity = new schema.Entity(
EntityType.NLU_HELPER,
undefined,
{
idAttribute: ({ name }) => name,
},
);
export const ENTITY_MAP = {
[EntityType.SUBSCRIBER]: SubscriberEntity,
[EntityType.LABEL]: LabelEntity,
@@ -310,4 +323,6 @@ export const ENTITY_MAP = {
[EntityType.CUSTOM_BLOCK]: CustomBlockEntity,
[EntityType.CUSTOM_BLOCK_SETTINGS]: CustomBlockSettingEntity,
[EntityType.CHANNEL]: ChannelEntity,
[EntityType.HELPER]: HelperEntity,
[EntityType.NLU_HELPER]: NluHelperEntity,
} as const;

View File

@@ -35,6 +35,8 @@ export enum EntityType {
TRANSLATION = "Translation",
ATTACHMENT = "Attachment",
CHANNEL = "Channel",
HELPER = "Helper",
NLU_HELPER = "NluHelper",
}
export type NormalizedEntities = Record<string, Record<string, any>>;

View File

@@ -22,6 +22,7 @@ import { IChannel, IChannelAttributes } from "./channel.types";
import { IContentType, IContentTypeAttributes } from "./content-type.types";
import { IContent, IContentAttributes, IContentFull } from "./content.types";
import { IContextVar, IContextVarAttributes } from "./context-var.types";
import { IHelper, IHelperAttributes } from "./helper.types";
import { ILabel, ILabelAttributes, ILabelFull } from "./label.types";
import { ILanguage, ILanguageAttributes } from "./language.types";
import {
@@ -112,6 +113,8 @@ export const POPULATE_BY_TYPE = {
[EntityType.CUSTOM_BLOCK]: [],
[EntityType.CUSTOM_BLOCK_SETTINGS]: [],
[EntityType.CHANNEL]: [],
[EntityType.HELPER]: [],
[EntityType.NLU_HELPER]: [],
} as const;
export type Populate<C extends EntityType> =
@@ -200,6 +203,8 @@ export interface IEntityMapTypes {
IMessageFull
>;
[EntityType.CHANNEL]: IEntityTypes<IChannelAttributes, IChannel>;
[EntityType.HELPER]: IEntityTypes<IHelperAttributes, IHelper>;
[EntityType.NLU_HELPER]: IEntityTypes<IHelperAttributes, IHelper>;
}
export type TType<TParam extends keyof IEntityMapTypes> =

View File

@@ -0,0 +1,16 @@
/*
* Copyright © 2024 Hexastack. All rights reserved.
*
* 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.
* 2. All derivative works must include clear attribution to the original creator and software, Hexastack and Hexabot, in a prominent location (e.g., in the software's "About" section, documentation, and README file).
*/
import { IBaseSchema } from "./base.types";
export interface IHelperAttributes {
name: string;
}
// @TODO: not all entities extend from IBaseSchema
export interface IHelper extends IHelperAttributes, IBaseSchema {}