perf: extract modules
This commit is contained in:
@@ -38,7 +38,7 @@ import { fileDownload } from '@/utils/file';
|
|||||||
import { htmlTemplate } from '@/constants/common';
|
import { htmlTemplate } from '@/constants/common';
|
||||||
import { useRouter } from 'next/router';
|
import { useRouter } from 'next/router';
|
||||||
import { useGlobalStore } from '@/store/global';
|
import { useGlobalStore } from '@/store/global';
|
||||||
import { TaskResponseKeyEnum } from '@/constants/chat';
|
import { TaskResponseKeyEnum, getDefaultChatVariables } from '@/constants/chat';
|
||||||
|
|
||||||
import MyIcon from '@/components/Icon';
|
import MyIcon from '@/components/Icon';
|
||||||
import Avatar from '@/components/Avatar';
|
import Avatar from '@/components/Avatar';
|
||||||
@@ -251,7 +251,7 @@ const ChatBox = (
|
|||||||
* user confirm send prompt
|
* user confirm send prompt
|
||||||
*/
|
*/
|
||||||
const sendPrompt = useCallback(
|
const sendPrompt = useCallback(
|
||||||
async (data: Record<string, any> = {}, inputVal = '') => {
|
async (variables: Record<string, any> = {}, inputVal = '') => {
|
||||||
if (isChatting) {
|
if (isChatting) {
|
||||||
toast({
|
toast({
|
||||||
title: '正在聊天中...请等待结束',
|
title: '正在聊天中...请等待结束',
|
||||||
@@ -306,7 +306,10 @@ const ChatBox = (
|
|||||||
messages,
|
messages,
|
||||||
controller: abortSignal,
|
controller: abortSignal,
|
||||||
generatingMessage,
|
generatingMessage,
|
||||||
variables: data
|
variables: {
|
||||||
|
...getDefaultChatVariables(),
|
||||||
|
...variables
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
// set finish status
|
// set finish status
|
||||||
|
|||||||
@@ -1,3 +1,5 @@
|
|||||||
|
import dayjs from 'dayjs';
|
||||||
|
|
||||||
export enum sseResponseEventEnum {
|
export enum sseResponseEventEnum {
|
||||||
error = 'error',
|
error = 'error',
|
||||||
answer = 'answer',
|
answer = 'answer',
|
||||||
@@ -65,3 +67,7 @@ export enum OutLinkTypeEnum {
|
|||||||
|
|
||||||
export const HUMAN_ICON = `https://fastgpt.run/icon/human.png`;
|
export const HUMAN_ICON = `https://fastgpt.run/icon/human.png`;
|
||||||
export const LOGO_ICON = `https://fastgpt.run/icon/logo.png`;
|
export const LOGO_ICON = `https://fastgpt.run/icon/logo.png`;
|
||||||
|
|
||||||
|
export const getDefaultChatVariables = () => ({
|
||||||
|
cTime: dayjs().format('YYYY/MM/DD HH:mm:ss')
|
||||||
|
});
|
||||||
|
|||||||
@@ -30,7 +30,7 @@ export const VariableModule: FlowModuleTemplateType = {
|
|||||||
name: '全局变量',
|
name: '全局变量',
|
||||||
intro: '可以在对话开始前,要求用户填写一些内容作为本轮对话的变量。该模块位于开场引导之后。',
|
intro: '可以在对话开始前,要求用户填写一些内容作为本轮对话的变量。该模块位于开场引导之后。',
|
||||||
description:
|
description:
|
||||||
'全局变量可以通过 {{变量key}} 的形式注入到其他模块的文本中。目前支持:提示词、限定词。',
|
'全局变量可以通过 {{变量key}} 的形式注入到其他模块 string 类型的输入中,例如:提示词、限定词等',
|
||||||
flowType: FlowModuleTypeEnum.variable,
|
flowType: FlowModuleTypeEnum.variable,
|
||||||
inputs: [
|
inputs: [
|
||||||
{
|
{
|
||||||
@@ -389,6 +389,7 @@ export const ContextExtractModule: FlowModuleTemplateType = {
|
|||||||
valueType: FlowValueTypeEnum.string,
|
valueType: FlowValueTypeEnum.string,
|
||||||
label: '提取要求描述',
|
label: '提取要求描述',
|
||||||
description: '写一段提取要求,告诉 AI 需要提取哪些内容',
|
description: '写一段提取要求,告诉 AI 需要提取哪些内容',
|
||||||
|
required: true,
|
||||||
placeholder:
|
placeholder:
|
||||||
'例如: \n1. 你是一个实验室预约助手。根据用户问题,提取出姓名、实验室号和预约时间',
|
'例如: \n1. 你是一个实验室预约助手。根据用户问题,提取出姓名、实验室号和预约时间',
|
||||||
value: ''
|
value: ''
|
||||||
@@ -433,8 +434,8 @@ export const ContextExtractModule: FlowModuleTemplateType = {
|
|||||||
{
|
{
|
||||||
key: ContextExtractEnum.fields,
|
key: ContextExtractEnum.fields,
|
||||||
label: '完整提取结果',
|
label: '完整提取结果',
|
||||||
description: '一个 JSON 对象,例如 {"name:":"YY","Time":"2023/7/2 18:00"}',
|
description: '一个 JSON 字符串,例如:{"name:":"YY","Time":"2023/7/2 18:00"}',
|
||||||
valueType: FlowValueTypeEnum.any,
|
valueType: FlowValueTypeEnum.string,
|
||||||
type: FlowOutputItemTypeEnum.source,
|
type: FlowOutputItemTypeEnum.source,
|
||||||
targets: []
|
targets: []
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -16,7 +16,7 @@ import { ContextExtractEnum } from '@/constants/flow/flowField';
|
|||||||
import { FlowOutputItemTypeEnum, FlowValueTypeEnum } from '@/constants/flow';
|
import { FlowOutputItemTypeEnum, FlowValueTypeEnum } from '@/constants/flow';
|
||||||
|
|
||||||
const NodeExtract = ({
|
const NodeExtract = ({
|
||||||
data: { inputs, outputs, moduleId, onChangeNode, ...props }
|
data: { inputs, outputs, moduleId, onChangeNode, onDelEdge, ...props }
|
||||||
}: NodeProps<FlowModuleItemType>) => {
|
}: NodeProps<FlowModuleItemType>) => {
|
||||||
const { t } = useTranslation();
|
const { t } = useTranslation();
|
||||||
const [editExtractFiled, setEditExtractField] = useState<ContextExtractAgentItemType>();
|
const [editExtractFiled, setEditExtractField] = useState<ContextExtractAgentItemType>();
|
||||||
@@ -105,6 +105,7 @@ const NodeExtract = ({
|
|||||||
key: '',
|
key: '',
|
||||||
value: newOutputVal
|
value: newOutputVal
|
||||||
});
|
});
|
||||||
|
onDelEdge({ moduleId, sourceHandle: item.key });
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
</Td>
|
</Td>
|
||||||
@@ -168,6 +169,10 @@ const NodeExtract = ({
|
|||||||
value: newOutputs
|
value: newOutputs
|
||||||
});
|
});
|
||||||
|
|
||||||
|
if (editExtractFiled.key && editExtractFiled.key !== data.key) {
|
||||||
|
onDelEdge({ moduleId, sourceHandle: editExtractFiled.key });
|
||||||
|
}
|
||||||
|
|
||||||
setEditExtractField(undefined);
|
setEditExtractField(undefined);
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
|
|||||||
@@ -162,7 +162,6 @@ const AppEdit = ({ app, fullScreen, onFullScreen }: Props) => {
|
|||||||
});
|
});
|
||||||
return modules;
|
return modules;
|
||||||
}, [edges, nodes]);
|
}, [edges, nodes]);
|
||||||
|
|
||||||
const onChangeNode = useCallback(
|
const onChangeNode = useCallback(
|
||||||
({ moduleId, key, type = 'inputs', value, valueKey = 'value' }: FlowModuleItemChangeProps) => {
|
({ moduleId, key, type = 'inputs', value, valueKey = 'value' }: FlowModuleItemChangeProps) => {
|
||||||
setNodes((nodes) =>
|
setNodes((nodes) =>
|
||||||
@@ -205,6 +204,29 @@ const AppEdit = ({ app, fullScreen, onFullScreen }: Props) => {
|
|||||||
},
|
},
|
||||||
[setEdges, setNodes]
|
[setEdges, setNodes]
|
||||||
);
|
);
|
||||||
|
const onDelEdge = useCallback(
|
||||||
|
({
|
||||||
|
moduleId,
|
||||||
|
sourceHandle,
|
||||||
|
targetHandle
|
||||||
|
}: {
|
||||||
|
moduleId: string;
|
||||||
|
sourceHandle?: string;
|
||||||
|
targetHandle?: string;
|
||||||
|
}) => {
|
||||||
|
if (!sourceHandle && !targetHandle) return;
|
||||||
|
setEdges((state) =>
|
||||||
|
state.filter((edge) => {
|
||||||
|
if (edge.source === moduleId && edge.sourceHandle === sourceHandle) return false;
|
||||||
|
if (edge.target === moduleId && edge.targetHandle === targetHandle) return false;
|
||||||
|
|
||||||
|
return true;
|
||||||
|
})
|
||||||
|
);
|
||||||
|
},
|
||||||
|
[setEdges]
|
||||||
|
);
|
||||||
|
|
||||||
const onAddNode = useCallback(
|
const onAddNode = useCallback(
|
||||||
({ template, position }: { template: FlowModuleTemplateType; position: XYPosition }) => {
|
({ template, position }: { template: FlowModuleTemplateType; position: XYPosition }) => {
|
||||||
if (!reactFlowWrapper.current) return;
|
if (!reactFlowWrapper.current) return;
|
||||||
@@ -221,12 +243,13 @@ const AppEdit = ({ app, fullScreen, onFullScreen }: Props) => {
|
|||||||
position: { x: mouseX, y: mouseY }
|
position: { x: mouseX, y: mouseY }
|
||||||
},
|
},
|
||||||
onChangeNode,
|
onChangeNode,
|
||||||
onDelNode
|
onDelNode,
|
||||||
|
onDelEdge
|
||||||
})
|
})
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
[onChangeNode, onDelNode, setNodes, x, y, zoom]
|
[onDelEdge, onChangeNode, onDelNode, setNodes, x, y, zoom]
|
||||||
);
|
);
|
||||||
const onDelConnect = useCallback(
|
const onDelConnect = useCallback(
|
||||||
(id: string) => {
|
(id: string) => {
|
||||||
@@ -309,14 +332,15 @@ const AppEdit = ({ app, fullScreen, onFullScreen }: Props) => {
|
|||||||
appModule2FlowNode({
|
appModule2FlowNode({
|
||||||
item,
|
item,
|
||||||
onChangeNode,
|
onChangeNode,
|
||||||
onDelNode
|
onDelNode,
|
||||||
|
onDelEdge
|
||||||
})
|
})
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
onFixView();
|
onFixView();
|
||||||
},
|
},
|
||||||
[onDelConnect, setEdges, setNodes, onFixView, onChangeNode, onDelNode]
|
[onDelConnect, setEdges, setNodes, onFixView, onChangeNode, onDelNode, onDelEdge]
|
||||||
);
|
);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
|
|||||||
@@ -19,7 +19,7 @@ export type Props = {
|
|||||||
export type Response = {
|
export type Response = {
|
||||||
[ContextExtractEnum.success]?: boolean;
|
[ContextExtractEnum.success]?: boolean;
|
||||||
[ContextExtractEnum.failed]?: boolean;
|
[ContextExtractEnum.failed]?: boolean;
|
||||||
[ContextExtractEnum.fields]: Record<string, any>;
|
[ContextExtractEnum.fields]: string;
|
||||||
[TaskResponseKeyEnum.responseData]: ChatHistoryItemResType;
|
[TaskResponseKeyEnum.responseData]: ChatHistoryItemResType;
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -115,7 +115,7 @@ export async function dispatchContentExtract({
|
|||||||
return {
|
return {
|
||||||
[ContextExtractEnum.success]: success ? true : undefined,
|
[ContextExtractEnum.success]: success ? true : undefined,
|
||||||
[ContextExtractEnum.failed]: success ? undefined : true,
|
[ContextExtractEnum.failed]: success ? undefined : true,
|
||||||
[ContextExtractEnum.fields]: arg,
|
[ContextExtractEnum.fields]: JSON.stringify(arg),
|
||||||
...arg,
|
...arg,
|
||||||
[TaskResponseKeyEnum.responseData]: {
|
[TaskResponseKeyEnum.responseData]: {
|
||||||
moduleName: ChatModuleEnum.Extract,
|
moduleName: ChatModuleEnum.Extract,
|
||||||
|
|||||||
9
client/src/types/flow.d.ts
vendored
9
client/src/types/flow.d.ts
vendored
@@ -59,4 +59,13 @@ export type FlowModuleItemType = FlowModuleTemplateType & {
|
|||||||
moduleId: string;
|
moduleId: string;
|
||||||
onChangeNode: (e: FlowModuleItemChangeProps) => void;
|
onChangeNode: (e: FlowModuleItemChangeProps) => void;
|
||||||
onDelNode: (id: string) => void;
|
onDelNode: (id: string) => void;
|
||||||
|
onDelEdge: ({
|
||||||
|
moduleId,
|
||||||
|
sourceHandle,
|
||||||
|
targetHandle
|
||||||
|
}: {
|
||||||
|
moduleId: string;
|
||||||
|
sourceHandle?: string | undefined;
|
||||||
|
targetHandle?: string | undefined;
|
||||||
|
}) => void;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -63,11 +63,13 @@ export const textAdaptGptResponse = ({
|
|||||||
export const appModule2FlowNode = ({
|
export const appModule2FlowNode = ({
|
||||||
item,
|
item,
|
||||||
onChangeNode,
|
onChangeNode,
|
||||||
onDelNode
|
onDelNode,
|
||||||
|
onDelEdge
|
||||||
}: {
|
}: {
|
||||||
item: AppModuleItemType;
|
item: AppModuleItemType;
|
||||||
onChangeNode: FlowModuleItemType['onChangeNode'];
|
onChangeNode: FlowModuleItemType['onChangeNode'];
|
||||||
onDelNode: FlowModuleItemType['onDelNode'];
|
onDelNode: FlowModuleItemType['onDelNode'];
|
||||||
|
onDelEdge: FlowModuleItemType['onDelEdge'];
|
||||||
}): Node<FlowModuleItemType> => {
|
}): Node<FlowModuleItemType> => {
|
||||||
// init some static data
|
// init some static data
|
||||||
const template =
|
const template =
|
||||||
@@ -96,7 +98,8 @@ export const appModule2FlowNode = ({
|
|||||||
};
|
};
|
||||||
}),
|
}),
|
||||||
onChangeNode,
|
onChangeNode,
|
||||||
onDelNode
|
onDelNode,
|
||||||
|
onDelEdge
|
||||||
};
|
};
|
||||||
|
|
||||||
return {
|
return {
|
||||||
|
|||||||
Reference in New Issue
Block a user