Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 16 additions & 1 deletion src/definition/helper/userPreference.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,27 @@ export enum AIProviderEnum {
SelfHosted = 'Self Hosted',
}

export enum PromptOptionsEnum {
Professional = 'Professional',
Friendly = 'Friendly',
Supportive = 'Supportive',
Concise = 'Concise',
Detailed = 'Detailed',
Actionable = 'Actionable',
Persuasive = 'Persuasive',
Analytical = 'Analytical',
Neutral = 'Neutral',
Helpful = 'Helpful',
}

export type PromptOptions = keyof typeof PromptOptionsEnum;

export interface IPreference {
userId: string;
language: Language;
AIusagePreference: AIusagePreference;
AIconfiguration: {
AIPrompt: string;
AIPromptOptions: PromptOptions[];
AIProvider: AIProviderType;
selfHosted: {
url: string;
Expand Down
17 changes: 17 additions & 0 deletions src/definition/ui-kit/Element/IMultiStaticSelectElement.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { MultiStaticSelectElement } from '@rocket.chat/ui-kit';

export type MultiStaticSelectElementParam = Pick<
MultiStaticSelectElement,
| 'options'
| 'optionGroups'
| 'initialOption'
| 'initialValue'
| 'dispatchActionConfig'
> & { placeholder: string };

export type MultiStaticSelectOptionsParam = Array<{
text: string;
value: string;
description?: string;
url?: string;
}>;
4 changes: 2 additions & 2 deletions src/enum/modals/UserPreferenceModal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ export enum UserPreferenceModalEnum {
GEMINI_API_KEY_BLOCK_ID = 'gemini-api-key-block-id',
SELF_HOSTED_URL_ACTION_ID = 'self-hosted-url-action-id',
SELF_HOSTED_URL_BLOCK_ID = 'self-hosted-url-block-id',
PROMPT_CONFIG_INPUT_BLOCK_ID = 'prompt-config-input-block-id',
PROMPT_CONFIG_INPUT_ACTION_ID = 'prompt-config-input-action-id',
PROMPT_CONFIG_OPTIONS_BLOCK_ID = 'prompt-config-options-block-id',
PROMPT_CONFIG_OPTIONS_ACTION_ID = 'prompt-config-options-action-id',

SUBMIT_ACTION_ID = 'submit-set-user-preference-language-modal-action-id',
SUBMIT_BLOCK_ID = 'submit-set-user-preference-language-modal-block-id',
Expand Down
2 changes: 1 addition & 1 deletion src/handlers/AIHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ class AIHandler {
}

private getPrompt(message: string, prompt: string): string {
return `Write a reply to this message: "${message}". ${this.userPreference.AIconfiguration.AIPrompt} and Use the following as a prompt or response reply: "${prompt}" and make sure you respond with just the reply without quotes.`;
return `Write a reply to this message: "${message}".Reply must be ${this.userPreference.AIconfiguration.AIPromptOptions} Use the as a prompt or response reply: "${prompt}" and make sure you respond with just the reply without quotes.`;
}

private async handleSelfHostedModel(
Expand Down
8 changes: 4 additions & 4 deletions src/handlers/ExecuteViewSubmitHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -210,10 +210,10 @@ export class ExecuteViewSubmitHandler {
UserPreferenceModalEnum.SELF_HOSTED_URL_ACTION_ID
];

const PromptConfigurationInput =
const PromptConfigurationOptions =
view.state?.[
UserPreferenceModalEnum.PROMPT_CONFIG_INPUT_BLOCK_ID
]?.[UserPreferenceModalEnum.PROMPT_CONFIG_INPUT_ACTION_ID];
UserPreferenceModalEnum.PROMPT_CONFIG_OPTIONS_BLOCK_ID
]?.[UserPreferenceModalEnum.PROMPT_CONFIG_OPTIONS_ACTION_ID];

const userPreference = new UserPreferenceStorage(
this.persistence,
Expand All @@ -226,7 +226,7 @@ export class ExecuteViewSubmitHandler {
language: languageInput,
AIusagePreference: AIpreferenceInput,
AIconfiguration: {
AIPrompt: PromptConfigurationInput,
AIPromptOptions: PromptConfigurationOptions,
AIProvider: AIoptionInput,
openAI: {
apiKey: OpenAIAPIKeyInput,
Expand Down
63 changes: 63 additions & 0 deletions src/lib/ElementBuilder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,17 @@ import {
PlainTextInputElement,
Option,
StaticSelectElement,
MultiStaticSelectElement,
} from '@rocket.chat/ui-kit';
import { PlainTextInputParam } from '../definition/ui-kit/Element/IPlainTextInputElement';
import {
StaticSelectElementParam,
StaticSelectOptionsParam,
} from '../definition/ui-kit/Element/IStaticSelectElement';
import {
MultiStaticSelectElementParam,
MultiStaticSelectOptionsParam,
} from '../definition/ui-kit/Element/IMultiStaticSelectElement';

export class ElementBuilder implements IElementBuilder {
constructor(private readonly appId: string) {}
Expand Down Expand Up @@ -146,4 +151,62 @@ export class ElementBuilder implements IElementBuilder {
});
return options;
}

public addMultiSelect(
param: MultiStaticSelectElementParam,
interaction: ElementInteractionParam,
): MultiStaticSelectElement {
const {
placeholder,
options,
optionGroups,
initialOption,
initialValue,
dispatchActionConfig,
} = param;
const { blockId, actionId } = interaction;
const multiSelect: MultiStaticSelectElement = {
type: BlockElementType.MULTI_STATIC_SELECT,
placeholder: {
type: TextObjectType.PLAIN_TEXT,
text: placeholder,
},
options,
optionGroups,
initialOption,
initialValue,
appId: this.appId,
blockId,
actionId,
dispatchActionConfig,
};
return multiSelect;
}

public createMultiSelectOptions(
param: MultiStaticSelectOptionsParam,
): Array<Option> {
const options: Array<Option> = param.map((option) => {
const { text, value, description, url } = option;
const optionObject: Option = {
text: {
type: TextObjectType.PLAIN_TEXT,
text,
},
value,
...(description
? {
description: {
type: TextObjectType.PLAIN_TEXT,
text: description,
},
// eslint-disable-next-line no-mixed-spaces-and-tabs
}
: undefined),
url,
};
return optionObject;
});
return options;
}
}
4 changes: 2 additions & 2 deletions src/lib/Translation/locales/de.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,8 @@ export const de = {
Generated_Response_Label: "KI-Antwort",
Generate_Modal_Title: "KI-Antwort generieren",
Send_This_Text: "Diese Antwort senden",
AI_Prompt_Input_Label: "AI-Konfigurationsaufforderung",
AI_Prompt_Input_Placeholder: "Geben Sie die AI-Konfigurationsaufforderung ein",
AI_Prompt_Options_Label: "AI-Eingabeaufforderungsoptionen",
AI_Prompt_Options_Placeholder: "Wählen Sie AI-Konfigurationsoptionen",
AI_Not_Configured_Personal: "AI ist nicht konfiguriert. Bitte überprüfen Sie Ihre Konfiguration, um diese Funktion zu nutzen.",
AI_Not_Configured_Admin: "AI ist nicht konfiguriert. Bitte kontaktieren Sie Ihren Administrator, um diese Funktion zu nutzen.",
AI_Self_Hosted_Model_Not_Configured: "Ihr selbst gehostetes Modell ist nicht richtig eingerichtet. Bitte überprüfen Sie Ihre Konfiguration",
Expand Down
4 changes: 2 additions & 2 deletions src/lib/Translation/locales/en.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,8 @@ export const en = {
Generated_Response_Label: "AI Response",
Generate_Modal_Title: "Generate AI Response",
Send_This_Text: "Send this reply",
AI_Prompt_Input_Label : "AI Configuration Prompt",
AI_Prompt_Input_Placeholder : "Enter the AI Configuration Prompt",
AI_Prompt_Options_Label : "AI Prompt Options",
AI_Prompt_Options_Placeholder : "Select AI Configuration Options",
AI_Not_Configured_Personal: "AI is not configured. Please Check your configuration to use this feature.",
AI_Not_Configured_Admin: "AI is not configured. Please contact your administrator to use this feature.",
AI_Self_Hosted_Model_Not_Configured: "Your Self Hosted Model is not set up properly. Please check your configuration",
Expand Down
4 changes: 2 additions & 2 deletions src/lib/Translation/locales/pl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,8 @@ export const pl = {
Generated_Response_Label: "Odpowiedź AI",
Generate_Modal_Title: "Generuj odpowiedź AI",
Send_This_Text: "Wyślij tę odpowiedź",
AI_Prompt_Input_Label: "Prompt konfiguracji AI",
AI_Prompt_Input_Placeholder: "Wprowadź prompt konfiguracji AI",
AI_Prompt_Options_Label: "Opcje podpowiedzi AI",
AI_Prompt_Options_Placeholder: "Wybierz Opcje konfiguracji AI",
AI_Not_Configured_Personal: "AI nie jest skonfigurowane. Proszę sprawdzić swoją konfigurację, aby skorzystać z tej funkcji.",
AI_Not_Configured_Admin: "AI nie jest skonfigurowane. Proszę skontaktować się z administratorem, aby skorzystać z tej funkcji.",
AI_Self_Hosted_Model_Not_Configured: "Twój model hostowany lokalnie nie jest poprawnie skonfigurowany. Proszę sprawdzić swoją konfigurację",
Expand Down
4 changes: 2 additions & 2 deletions src/lib/Translation/locales/pt.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,8 @@ export const pt = {
Generated_Response_Label: "Resposta da IA",
Generate_Modal_Title: "Gerar Resposta da IA",
Send_This_Text: "Enviar esta resposta",
AI_Prompt_Input_Label: "Prompt de Configuração de IA",
AI_Prompt_Input_Placeholder: "Digite o Prompt de Configuração de IA",
AI_Prompt_Options_Label: "Opções de prompt de IA",
AI_Prompt_Options_Placeholder: "Selecione opções de configuração de IA",
AI_Not_Configured_Personal: "IA não está configurada. Por favor, verifique sua configuração para usar este recurso.",
AI_Not_Configured_Admin: "IA não está configurada. Por favor, entre em contato com o administrador para usar este recurso.",
AI_Self_Hosted_Model_Not_Configured: "Seu Modelo Auto-Hospedado não está configurado corretamente. Por favor, verifique sua configuração",
Expand Down
4 changes: 2 additions & 2 deletions src/lib/Translation/locales/ru.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,8 @@ export const ru = {
Generated_Response_Label: "Ответ ИИ",
Generate_Modal_Title: "Сгенерировать ответ ИИ",
Send_This_Text: "Отправить этот ответ",
AI_Prompt_Input_Label: "Запрос конфигурации ИИ",
AI_Prompt_Input_Placeholder: "Введите запрос конфигурации ИИ",
AI_Prompt_Options_Label: "Параметры подсказок ИИ",
AI_Prompt_Options_Placeholder: "Выберите параметры конфигурации AI",
AI_Not_Configured_Personal: "ИИ не настроен. Пожалуйста, проверьте свою конфигурацию, чтобы использовать эту функцию.",
AI_Not_Configured_Admin: "ИИ не настроен. Пожалуйста, свяжитесь с администратором, чтобы использовать эту функцию.",
AI_Self_Hosted_Model_Not_Configured: "Ваша собственная модель не настроена должным образом. Пожалуйста, проверьте свою конфигурацию",
Expand Down
36 changes: 27 additions & 9 deletions src/modal/UserPreferenceModal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import {
AIProviderEnum,
AIusagePreferenceEnum,
IPreference,
PromptOptionsEnum,
} from '../definition/helper/userPreference';
import { inputElementComponent } from './common/inputElementComponent';

Expand Down Expand Up @@ -73,21 +74,38 @@ export async function UserPreferenceModal({
);

blocks.push(blockBuilder.createDividerBlock());
const PromptInput = inputElementComponent(

const promptOptions = Object.values(PromptOptionsEnum).map((option) => ({
text: option,
value: option,
}));

const promptMultiSelectOptions =
elementBuilder.createMultiSelectOptions(promptOptions);

const promptMultiSelect = elementBuilder.addMultiSelect(
{
app,
label: t('AI_Prompt_Input_Label', language),
placeholder: t('AI_Prompt_Input_Placeholder', language),
optional: false,
initialValue: existingPreference?.AIconfiguration?.AIPrompt,
placeholder: t('AI_Prompt_Options_Placeholder', language),
options: promptMultiSelectOptions,
initialValue:
existingPreference.AIconfiguration?.AIPromptOptions?.map(
(option) => option,
),
dispatchActionConfig: [Modals.dispatchActionConfigOnSelect],
},
{
blockId: UserPreferenceModalEnum.PROMPT_CONFIG_INPUT_BLOCK_ID,
actionId: UserPreferenceModalEnum.PROMPT_CONFIG_INPUT_ACTION_ID,
blockId: UserPreferenceModalEnum.PROMPT_CONFIG_OPTIONS_BLOCK_ID,
actionId: UserPreferenceModalEnum.PROMPT_CONFIG_OPTIONS_ACTION_ID,
},
);

blocks.push(PromptInput);
blocks.push(
blockBuilder.createInputBlock({
text: t('AI_Prompt_Options_Label', language),
element: promptMultiSelect,
optional: false,
}),
);

const AIusagePreferenceOptions = [
{
Expand Down
8 changes: 4 additions & 4 deletions src/storage/userPreferenceStorage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,9 @@ export class UserPreferenceStorage implements IuserPreferenceStorage {
preference.AIusagePreference ||
currentPreference.AIusagePreference,
AIconfiguration: {
AIPrompt:
preference.AIconfiguration.AIPrompt ||
currentPreference.AIconfiguration.AIPrompt,
AIPromptOptions:
preference.AIconfiguration.AIPromptOptions ||
currentPreference.AIconfiguration.AIPromptOptions,
AIProvider:
preference.AIconfiguration.AIProvider ||
currentPreference.AIconfiguration.AIProvider,
Expand Down Expand Up @@ -89,7 +89,7 @@ export class UserPreferenceStorage implements IuserPreferenceStorage {
language: Language.en,
AIusagePreference: AIusagePreferenceEnum.Workspace,
AIconfiguration: {
AIPrompt: `Keep the comprehensive clear and concise reply, and ensure it's well-articulated and helpfull`,
AIPromptOptions: ['Professional', 'Concise', 'Helpful'],
AIProvider: AIProviderEnum.SelfHosted,
gemini: {
apiKey: '',
Expand Down