Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

perf: all plugin variables type support referense & replace input and textarea with prompt editor #2950

Merged
merged 4 commits into from
Oct 22, 2024
Merged
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
7 changes: 7 additions & 0 deletions packages/global/core/workflow/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,7 @@ export enum NodeOutputKeyEnum {
export enum VariableInputEnum {
input = 'input',
textarea = 'textarea',
textInput = 'textInput',
numberInput = 'numberInput',
select = 'select',
custom = 'custom'
Expand Down Expand Up @@ -294,6 +295,12 @@ export const variableMap: Record<
defaultValueType: WorkflowIOValueTypeEnum.string,
description: i18nT('app:variable.textarea_type_desc')
},
[VariableInputEnum.textInput]: {
icon: 'core/workflow/inputType/input',
label: i18nT('common:core.workflow.inputType.textInput'),
value: VariableInputEnum.textInput,
defaultValueType: WorkflowIOValueTypeEnum.string
},
[VariableInputEnum.numberInput]: {
icon: 'core/workflow/inputType/numberInput',
label: i18nT('common:core.workflow.inputType.number input'),
Expand Down
24 changes: 15 additions & 9 deletions packages/global/core/workflow/node/constant.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
import { WorkflowIOValueTypeEnum } from '../constants';
import { i18nT } from '../../../../web/i18n/utils';
export enum FlowNodeInputTypeEnum { // render ui
textInput = 'textInput',
reference = 'reference', // reference to other node output
input = 'input', // one line input
numberInput = 'numberInput',
switch = 'switch', // true/false
select = 'select',

// editor
textarea = 'textarea',
JSONEditor = 'JSONEditor',

addInputParam = 'addInputParam', // params input
Expand All @@ -27,20 +26,24 @@ export enum FlowNodeInputTypeEnum { // render ui
settingDatasetQuotePrompt = 'settingDatasetQuotePrompt',

hidden = 'hidden',
custom = 'custom'
custom = 'custom',

// deprecated
input = 'input', // one line input
textarea = 'textarea'
}
export const FlowNodeInputMap: Record<
FlowNodeInputTypeEnum,
{
icon: string;
}
> = {
[FlowNodeInputTypeEnum.textInput]: {
icon: 'core/workflow/inputType/input'
},
[FlowNodeInputTypeEnum.reference]: {
icon: 'core/workflow/inputType/reference'
},
[FlowNodeInputTypeEnum.input]: {
icon: 'core/workflow/inputType/input'
},
[FlowNodeInputTypeEnum.numberInput]: {
icon: 'core/workflow/inputType/numberInput'
},
Expand All @@ -50,9 +53,6 @@ export const FlowNodeInputMap: Record<
[FlowNodeInputTypeEnum.switch]: {
icon: 'core/workflow/inputType/switch'
},
[FlowNodeInputTypeEnum.textarea]: {
icon: 'core/workflow/inputType/textarea'
},
[FlowNodeInputTypeEnum.JSONEditor]: {
icon: 'core/workflow/inputType/jsonEditor'
},
Expand Down Expand Up @@ -85,6 +85,12 @@ export const FlowNodeInputMap: Record<
},
[FlowNodeInputTypeEnum.custom]: {
icon: 'core/workflow/inputType/custom'
},
[FlowNodeInputTypeEnum.input]: {
icon: 'core/workflow/inputType/input'
},
[FlowNodeInputTypeEnum.textarea]: {
icon: 'core/workflow/inputType/textarea'
}
};

Expand Down
4 changes: 4 additions & 0 deletions packages/global/core/workflow/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,10 @@ export const appData2FlowNodeIO = ({
FlowNodeInputTypeEnum.textarea,
FlowNodeInputTypeEnum.reference
],
[VariableInputEnum.textInput]: [
FlowNodeInputTypeEnum.textInput,
FlowNodeInputTypeEnum.reference
],
[VariableInputEnum.numberInput]: [FlowNodeInputTypeEnum.numberInput],
[VariableInputEnum.select]: [FlowNodeInputTypeEnum.select],
[VariableInputEnum.custom]: [
Expand Down
5 changes: 5 additions & 0 deletions packages/web/components/core/workflow/NodeInputSelect.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,11 @@ const NodeInputSelect = ({
icon: FlowNodeInputMap[FlowNodeInputTypeEnum.input].icon,
title: t('common:core.workflow.inputType.Manual input')
},
{
type: FlowNodeInputTypeEnum.textInput,
icon: FlowNodeInputMap[FlowNodeInputTypeEnum.input].icon,
title: t('common:core.workflow.inputType.Manual input')
},
{
type: FlowNodeInputTypeEnum.numberInput,
icon: FlowNodeInputMap[FlowNodeInputTypeEnum.numberInput].icon,
Expand Down
1 change: 1 addition & 0 deletions packages/web/i18n/en/common.json
Original file line number Diff line number Diff line change
Expand Up @@ -800,6 +800,7 @@
"core.workflow.inputType.selectDataset": "Dataset Select",
"core.workflow.inputType.selectLLMModel": "Chat Model Select",
"core.workflow.inputType.switch": "Switch",
"core.workflow.inputType.textInput": "Text Input box",
"core.workflow.inputType.textarea": "Multi-line Input Box",
"core.workflow.publish.OnRevert version": "Click to Revert to This Version",
"core.workflow.publish.OnRevert version confirm": "Confirm to Revert to This Version? The configuration of the editing version will be saved, and a new release version will be created for the reverted version.",
Expand Down
3 changes: 2 additions & 1 deletion packages/web/i18n/en/workflow.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
"Array_element": "Array element",
"Code": "Code",
"Confirm_sync_node": "It will be updated to the latest node configuration and fields that do not exist in the template will be deleted (including all custom fields).\n\nIf the fields are complex, it is recommended that you copy a node first and then update the original node to facilitate parameter copying.",
"Node_variables": "Node variables",
"Node.Open_Node_Course": "Open node course",
"Node_variables": "Node variables",
"Quote_prompt_setting": "Quote prompt",
"Variable.Variable type": "Variable type",
"Variable_name": "Variable name",
Expand Down Expand Up @@ -54,6 +54,7 @@
"field_description_placeholder": "Describe the function of this input field. If it is a tool call parameter, this description will affect the quality of the model generation.",
"field_name_already_exists": "Field name already exists",
"field_required": "Required",
"field_used_as_reference": "Support reference",
"field_used_as_tool_input": "Used as Tool Call Parameter",
"filter_description": "Currently supports filtering by tags and creation time. Fill in the format as follows:\n{\n \"tags\": {\n \"$and\": [\"Tag 1\",\"Tag 2\"],\n \"$or\": [\"When there are $and tags, and is effective, or is not effective\"]\n },\n \"createTime\": {\n \"$gte\": \"YYYY-MM-DD HH:mm format, collection creation time greater than this time\",\n \"$lte\": \"YYYY-MM-DD HH:mm format, collection creation time less than this time, can be used with $gte\"\n }\n}",
"form_input_result": "User complete input result",
Expand Down
1 change: 1 addition & 0 deletions packages/web/i18n/zh/common.json
Original file line number Diff line number Diff line change
Expand Up @@ -805,6 +805,7 @@
"core.workflow.inputType.selectDataset": "知识库选择",
"core.workflow.inputType.selectLLMModel": "对话模型选择",
"core.workflow.inputType.switch": "开关",
"core.workflow.inputType.textInput": "文本输入框",
"core.workflow.inputType.textarea": "多行输入框",
"core.workflow.publish.OnRevert version": "点击回退到该版本",
"core.workflow.publish.OnRevert version confirm": "确认回退至该版本?会为您保存编辑中版本的配置,并为回退版本创建一个新的发布版本。",
Expand Down
3 changes: 2 additions & 1 deletion packages/web/i18n/zh/workflow.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
"Array_element": "数组元素",
"Code": "代码",
"Confirm_sync_node": "将会更新至最新的节点配置,不存在模板中的字段将会被删除(包括所有自定义字段)。\n如果字段较为复杂,建议您先复制一份节点,再更新原来的节点,便于参数复制。",
"Node_variables": "节点变量",
"Node.Open_Node_Course": "查看节点教程",
"Node_variables": "节点变量",
"Quote_prompt_setting": "引用提示词配置",
"Variable.Variable type": "变量类型",
"Variable_name": "变量名",
Expand Down Expand Up @@ -55,6 +55,7 @@
"field_description_placeholder": "描述该输入字段的功能,如果为工具调用参数,则该描述会影响模型生成的质量",
"field_name_already_exists": "字段名已经存在",
"field_required": "必填",
"field_used_as_reference": "支持变量引用",
"field_used_as_tool_input": "作为工具调用参数",
"filter_description": "目前支持标签和创建时间过滤,需按照以下格式填写:\n{\n \"tags\": {\n \"$and\": [\"标签 1\",\"标签 2\"],\n \"$or\": [\"有 $and 标签时,and 生效,or 不生效\"]\n },\n \"createTime\": {\n \"$gte\": \"YYYY-MM-DD HH:mm 格式即可,集合的创建时间大于该时间\",\n \"$lte\": \"YYYY-MM-DD HH:mm 格式即可,集合的创建时间小于该时间,可和 $gte 共同使用\"\n }\n}",
"form_input_result": "用户完整输入结果",
Expand Down
21 changes: 13 additions & 8 deletions projects/app/src/components/core/app/VariableEdit.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ export const defaultVariable: VariableItemType = {
id: nanoid(),
key: '',
label: '',
type: VariableInputEnum.input,
type: VariableInputEnum.textInput,
description: '',
required: true,
valueType: WorkflowIOValueTypeEnum.string
Expand Down Expand Up @@ -72,13 +72,18 @@ const VariableEdit = ({

const inputTypeList = useMemo(
() =>
Object.values(variableMap).map((item) => ({
icon: item.icon,
label: t(item.label as any),
value: item.value,
defaultValueType: item.defaultValueType,
description: item.description ? t(item.description as any) : ''
})),
Object.values(variableMap)
.filter(
(item) =>
item.value !== VariableInputEnum.input && item.value !== VariableInputEnum.textarea
)
.map((item) => ({
icon: item.icon,
label: t(item.label as any),
value: item.value,
defaultValueType: item.defaultValueType,
description: item.description ? t(item.description as any) : ''
})),
[t]
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import { ChatBoxContext } from '../Provider';
import QuestionTip from '@fastgpt/web/components/common/MyTooltip/QuestionTip';
import { useDeepCompareEffect } from 'ahooks';
import { VariableItemType } from '@fastgpt/global/core/app/type';
import PromptEditor from '@fastgpt/web/components/common/Textarea/PromptEditor';

export const VariableInputItem = ({
item,
Expand Down Expand Up @@ -77,6 +78,16 @@ export const VariableInputItem = ({
maxLength={item.maxLength || 4000}
/>
)}
{item.type === VariableInputEnum.textInput && (
<PromptEditor
value={item.defaultValue}
onChange={(e) => setValue(item.key, e)}
bg={'myGray.50'}
minH={50}
maxH={150}
showOpenModal={false}
/>
)}
{item.type === VariableInputEnum.select && (
<Controller
key={item.key}
Expand Down
10 changes: 10 additions & 0 deletions projects/app/src/components/core/chat/components/AIResponseBox.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ import { FlowNodeInputTypeEnum } from '@fastgpt/global/core/workflow/node/consta
import { useTranslation } from 'react-i18next';
import { Controller, useForm } from 'react-hook-form';
import MySelect from '@fastgpt/web/components/common/MySelect';
import PromptEditor from '@fastgpt/web/components/common/Textarea/PromptEditor';

type props = {
value: UserChatItemValueItemType | AIChatItemValueItemType;
Expand Down Expand Up @@ -240,6 +241,15 @@ const RenderUserFormInteractive = React.memo(function RenderFormInput({
maxLength={input.maxLength || 4000}
/>
)}
{input.type === FlowNodeInputTypeEnum.textInput && (
<PromptEditor
value={input.value}
onChange={(e) => setValue(input.label, e)}
minH={40}
maxH={100}
showOpenModal={false}
/>
)}
{input.type === FlowNodeInputTypeEnum.numberInput && (
<NumberInput
step={1}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import {
Box,
Button,
Flex,
Textarea,
NumberDecrementStepper,
NumberIncrementStepper,
NumberInput,
Expand All @@ -34,6 +33,7 @@ import { FlowNodeTypeEnum } from '@fastgpt/global/core/workflow/node/constant';
import { AppContext } from '../../../context';
import { VariableInputItem } from '@/components/core/chat/ChatContainer/ChatBox/components/VariableInput';
import LightRowTabs from '@fastgpt/web/components/common/Tabs/LightRowTabs';
import PromptEditor from '@fastgpt/web/components/common/Textarea/PromptEditor';

const MyRightDrawer = dynamic(
() => import('@fastgpt/web/components/common/MyDrawer/MyRightDrawer')
Expand Down Expand Up @@ -270,10 +270,14 @@ export const useDebug = () => {
const RenderInput = (() => {
if (input.valueType === WorkflowIOValueTypeEnum.string) {
return (
<Textarea
{...register(`nodeVariables.${input.key}`, {
required
})}
<PromptEditor
value={getValues(`nodeVariables.${input.key}`)}
onChange={(e) => {
setValue(`nodeVariables.${input.key}`, e);
}}
minH={50}
maxH={150}
showOpenModal={false}
placeholder={t(input.placeholder || ('' as any))}
bg={'myGray.50'}
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { useToast } from '@fastgpt/web/hooks/useToast';
import InputTypeConfig from '../NodePluginIO/InputTypeConfig';

export const defaultFormInput: UserInputFormItemType = {
type: FlowNodeInputTypeEnum.input,
type: FlowNodeInputTypeEnum.textInput,
key: '',
label: '',
description: '',
Expand Down Expand Up @@ -54,14 +54,8 @@ const InputFormEditModal = ({
const inputTypeList = [
{
icon: 'core/workflow/inputType/input',
label: t('common:core.workflow.inputType.input'),
value: FlowNodeInputTypeEnum.input,
defaultValueType: WorkflowIOValueTypeEnum.string
},
{
icon: 'core/workflow/inputType/textarea',
label: t('common:core.workflow.inputType.textarea'),
value: FlowNodeInputTypeEnum.textarea,
label: t('common:core.workflow.inputType.textInput'),
value: FlowNodeInputTypeEnum.textInput,
defaultValueType: WorkflowIOValueTypeEnum.string
},
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,14 +54,8 @@ const FieldEditModal = ({
},
{
icon: 'core/workflow/inputType/input',
label: t('common:core.workflow.inputType.input'),
value: FlowNodeInputTypeEnum.input,
defaultValueType: WorkflowIOValueTypeEnum.string
},
{
icon: 'core/workflow/inputType/textarea',
label: t('common:core.workflow.inputType.textarea'),
value: FlowNodeInputTypeEnum.textarea,
label: t('common:core.workflow.inputType.textInput'),
value: FlowNodeInputTypeEnum.textInput,
defaultValueType: WorkflowIOValueTypeEnum.string
},
{
Expand Down Expand Up @@ -138,11 +132,24 @@ const FieldEditModal = ({
});
const { getValues, setValue, watch, reset } = form;

const inputType = watch('renderTypeList.0') || FlowNodeInputTypeEnum.reference;
const renderTypeList = watch('renderTypeList');
const inputType = renderTypeList[0] || FlowNodeInputTypeEnum.reference;
const valueType = watch('valueType');

const [isToolInput, { toggle: setIsToolInput }] = useBoolean(!!getValues('toolDescription'));

const isRefrence = renderTypeList.includes(FlowNodeInputTypeEnum.reference);
const setIsRefrence = () => {
if (isRefrence) {
setValue(
'renderTypeList',
renderTypeList.filter((item) => item !== FlowNodeInputTypeEnum.reference)
);
} else {
setValue('renderTypeList', [...getValues('renderTypeList'), FlowNodeInputTypeEnum.reference]);
}
};

const maxLength = watch('maxLength');
const max = watch('max');
const min = watch('min');
Expand Down Expand Up @@ -328,6 +335,8 @@ const FieldEditModal = ({
defaultValue={defaultInputValue}
isToolInput={isToolInput}
setIsToolInput={setIsToolInput}
isRefrence={isRefrence}
setIsRefrence={setIsRefrence}
valueType={valueType}
defaultValueType={defaultValueType}
onSubmitSuccess={onSubmitSuccess}
Expand Down
Loading
Loading