mirror of
https://github.com/labring/FastGPT.git
synced 2025-07-24 22:03:54 +00:00
feat: get node variables in prompt editor (#2087)
* feat: get node variables in prompt editor * fix * fix build * merge * fix build * delete default parent * fix * fix
This commit is contained in:
Binary file not shown.
Before Width: | Height: | Size: 1.6 KiB After Width: | Height: | Size: 1.6 KiB |
@@ -13,7 +13,6 @@ import {
|
||||
} from '@chakra-ui/react';
|
||||
import { useForm } from 'react-hook-form';
|
||||
import MySlider from '@/components/Slider';
|
||||
import MyTooltip from '@fastgpt/web/components/common/MyTooltip';
|
||||
import MyModal from '@fastgpt/web/components/common/MyModal';
|
||||
import { DatasetSearchModeEnum } from '@fastgpt/global/core/dataset/constants';
|
||||
import { useTranslation } from 'next-i18next';
|
||||
|
@@ -18,7 +18,6 @@ const WelcomeTextConfig = (props: TextareaProps) => {
|
||||
</Flex>
|
||||
<MyTextarea
|
||||
mt={2}
|
||||
bg={'myWhite.400'}
|
||||
rows={6}
|
||||
fontSize={'sm'}
|
||||
placeholder={t('common:core.app.tip.welcomeTextTip')}
|
||||
|
@@ -107,7 +107,14 @@ const EditForm = ({
|
||||
formatEditorVariablePickerIcon([
|
||||
...getSystemVariables(t),
|
||||
...(appForm.chatConfig.variables || [])
|
||||
]),
|
||||
]).map((item) => ({
|
||||
...item,
|
||||
parent: {
|
||||
id: 'VARIABLE_NODE_ID',
|
||||
label: '全局变量',
|
||||
avatar: '/imgs/workflow/variable.png'
|
||||
}
|
||||
})),
|
||||
[appForm.chatConfig.variables, t]
|
||||
);
|
||||
|
||||
|
@@ -5,13 +5,15 @@ import PromptEditor from '@fastgpt/web/components/common/Textarea/PromptEditor';
|
||||
import { formatEditorVariablePickerIcon } from '@fastgpt/global/core/workflow/utils';
|
||||
import { useContextSelector } from 'use-context-selector';
|
||||
import { WorkflowContext } from '@/pages/app/detail/components/WorkflowComponents/context';
|
||||
import { getWorkflowGlobalVariables } from '@/web/core/workflow/utils';
|
||||
import { computedNodeInputReference } from '@/web/core/workflow/utils';
|
||||
import { useCreation } from 'ahooks';
|
||||
import { AppContext } from '@/pages/app/detail/components/context';
|
||||
import { WorkflowIOValueTypeEnum } from '@fastgpt/global/core/workflow/constants';
|
||||
|
||||
const TextareaRender = ({ inputs = [], item, nodeId }: RenderInputProps) => {
|
||||
const { t } = useTranslation();
|
||||
const nodeList = useContextSelector(WorkflowContext, (v) => v.nodeList);
|
||||
const edges = useContextSelector(WorkflowContext, (v) => v.edges);
|
||||
const onChangeNode = useContextSelector(WorkflowContext, (v) => v.onChangeNode);
|
||||
const getNodeDynamicInputs = useContextSelector(WorkflowContext, (v) => v.getNodeDynamicInputs);
|
||||
|
||||
@@ -19,20 +21,50 @@ const TextareaRender = ({ inputs = [], item, nodeId }: RenderInputProps) => {
|
||||
|
||||
// get variable
|
||||
const variables = useCreation(() => {
|
||||
const globalVariables = getWorkflowGlobalVariables({
|
||||
const currentNode = nodeList.find((node) => node.nodeId === nodeId);
|
||||
const nodeVariables = formatEditorVariablePickerIcon(
|
||||
getNodeDynamicInputs(nodeId).map((item) => ({
|
||||
key: item.key,
|
||||
label: item.label,
|
||||
parent: {
|
||||
id: currentNode?.nodeId,
|
||||
label: currentNode?.name,
|
||||
avatar: currentNode?.avatar
|
||||
}
|
||||
}))
|
||||
);
|
||||
|
||||
const sourceNodes = computedNodeInputReference({
|
||||
nodeId,
|
||||
nodes: nodeList,
|
||||
edges: edges,
|
||||
chatConfig: appDetail.chatConfig,
|
||||
t
|
||||
});
|
||||
|
||||
const nodeVariables = formatEditorVariablePickerIcon(
|
||||
getNodeDynamicInputs(nodeId).map((item) => ({
|
||||
key: item.key,
|
||||
label: item.label
|
||||
}))
|
||||
);
|
||||
const sourceNodeVariables = !sourceNodes
|
||||
? []
|
||||
: sourceNodes
|
||||
.map((node) => {
|
||||
return node.outputs
|
||||
.filter((output) => !!output.label)
|
||||
.map((output) => {
|
||||
return {
|
||||
label: t((output.label as any) || ''),
|
||||
key: output.id,
|
||||
parent: {
|
||||
id: node.nodeId,
|
||||
label: node.name,
|
||||
avatar: node.avatar
|
||||
}
|
||||
};
|
||||
});
|
||||
})
|
||||
.flat();
|
||||
|
||||
return [...globalVariables, ...nodeVariables];
|
||||
const formatSourceNodeVariables = formatEditorVariablePickerIcon(sourceNodeVariables);
|
||||
|
||||
return [...nodeVariables, ...formatSourceNodeVariables];
|
||||
}, [nodeList, inputs, t]);
|
||||
|
||||
const onChange = useCallback(
|
||||
|
Reference in New Issue
Block a user