Skip to content

Commit

Permalink
4.8 test fix (#1385)
Browse files Browse the repository at this point in the history
* fix: tool name cannot startwith number

* fix: chatbox update

* fix: chatbox

* perf: drag ui

* perf: drag component

* drag component
  • Loading branch information
c121914yu committed May 7, 2024
1 parent 2a99e46 commit fef1a17
Show file tree
Hide file tree
Showing 16 changed files with 203 additions and 118 deletions.
20 changes: 12 additions & 8 deletions docSite/content/docs/development/upgrading/48.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
title: 'V4.8(进行中)'
title: 'V4.8(开发中)'
description: 'FastGPT V4.8 更新说明'
icon: 'upgrade'
draft: false
Expand All @@ -18,10 +18,14 @@ FastGPT workflow V2上线,支持更加简洁的工作流模式。
## V4.8 更新说明

1. 重构 - 工作流
2. 新增 - 工作流 Debug 模式,可以调试单个节点或者逐步调试工作流。
3. 新增 - 定时执行应用。可轻松实现定时任务。
4. 新增 - 插件自定义输入优化,可以渲染输入组件。
6. 优化 - 工作流连线,可以四向连接,方便构建循环工作流。
7. 优化 - 工作流上下文传递,性能🚀。
8. 优化 - 简易模式,更新配置后自动更新调试框内容,无需保存。
9. 优化 - worker进程管理,并将计算 Token 任务分配给 worker 进程。
2. 新增 - 判断器。支持 if elseIf else 判断。
3. 新增 - 变量更新节点。支持更新运行中工作流输出变量,或更新全局变量。
4. 新增 - 工作流 Debug 模式,可以调试单个节点或者逐步调试工作流。
5. 新增 - 定时执行应用。可轻松实现定时任务。
6. 新增 - 插件自定义输入优化,可以渲染输入组件。
7. 优化 - 工作流连线,可以四向连接,方便构建循环工作流。
8. 优化 - 工作流上下文传递,性能🚀。
9. 优化 - 简易模式,更新配置后自动更新调试框内容,无需保存。
10. 优化 - worker进程管理,并将计算 Token 任务分配给 worker 进程。
11. 修复 - 工具调用时候,name不能是数字开头(随机数有概率数字开头)
12. 修复 - 分享链接, query 全局变量会被缓存。
12 changes: 11 additions & 1 deletion packages/global/common/string/tools.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,18 @@ export const replaceSensitiveText = (text: string) => {
return text;
};

/* Make sure the first letter is definitely lowercase */
export const getNanoid = (size = 12) => {
return customAlphabet('abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890', size)();
const firstChar = customAlphabet('abcdefghijklmnopqrstuvwxyz', 1)();

if (size === 1) return firstChar;

const randomsStr = customAlphabet(
'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890',
size - 1
)();

return `${firstChar}${randomsStr}`;
};

export const replaceRegChars = (text: string) => text.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
3 changes: 2 additions & 1 deletion packages/global/core/workflow/template/input.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,10 @@ export const Input_Template_History: FlowNodeInputItemType = {
renderTypeList: [FlowNodeInputTypeEnum.numberInput, FlowNodeInputTypeEnum.reference],
valueType: WorkflowIOValueTypeEnum.chatHistory,
label: 'core.module.input.label.chat history',
description: '最多携带多少轮对话记录',
required: true,
min: 0,
max: 30,
max: 50,
value: 6
};

Expand Down
14 changes: 14 additions & 0 deletions packages/web/components/common/DndDrag/DragIcon.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { DragHandleIcon } from '@chakra-ui/icons';
import { Box } from '@chakra-ui/react';
import React from 'react';
import { DraggableProvided } from 'react-beautiful-dnd';

const DragIcon = ({ provided }: { provided: DraggableProvided }) => {
return (
<Box {...provided.dragHandleProps}>
<DragHandleIcon color={'myGray.500'} _hover={{ color: 'primary.600' }} />
</Box>
);
};

export default DragIcon;
61 changes: 61 additions & 0 deletions packages/web/components/common/DndDrag/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
import { Box } from '@chakra-ui/react';
import React, { useState } from 'react';
import {
DragDropContext,
DroppableProps,
Droppable,
DraggableChildrenFn,
DragStart,
DropResult
} from 'react-beautiful-dnd';

type Props<T = any> = {
onDragEndCb: (result: T[]) => void;
renderClone?: DraggableChildrenFn;
children: DroppableProps['children'];
dataList: T[];
};

function DndDrag<T>({ children, renderClone, onDragEndCb, dataList }: Props<T>) {
const [draggingItemHeight, setDraggingItemHeight] = useState(0);

const onDragStart = (start: DragStart) => {
const draggingNode = document.querySelector(`[data-rbd-draggable-id="${start.draggableId}"]`);
setDraggingItemHeight(draggingNode?.getBoundingClientRect().height || 0);
};

const onDragEnd = (result: DropResult) => {
if (!result.destination) {
return;
}
setDraggingItemHeight(0);

const startIndex = result.source.index;
const endIndex = result.destination.index;

const list = Array.from(dataList);
const [removed] = list.splice(startIndex, 1);
list.splice(endIndex, 0, removed);

onDragEndCb(list);
};

return (
<DragDropContext onDragStart={onDragStart} onDragEnd={onDragEnd}>
<Droppable droppableId="droppable" renderClone={renderClone}>
{(provided, snapshot) => {
return (
<Box {...provided.droppableProps} ref={provided.innerRef}>
{children(provided, snapshot)}
{snapshot.isDraggingOver && <Box height={draggingItemHeight} />}
</Box>
);
}}
</Droppable>
</DragDropContext>
);
}

export default DndDrag;

export * from 'react-beautiful-dnd';
6 changes: 4 additions & 2 deletions packages/web/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,14 @@
"react": "18.2.0",
"react-day-picker": "^8.7.1",
"react-dom": "18.2.0",
"react-i18next": "13.5.0"
"react-i18next": "13.5.0",
"react-beautiful-dnd": "^13.1.1"
},
"devDependencies": {
"@types/lodash": "^4.14.191",
"@types/papaparse": "^5.3.7",
"@types/react": "18.2.0",
"@types/react-dom": "18.2.0"
"@types/react-dom": "18.2.0",
"@types/react-beautiful-dnd": "^13.1.8"
}
}
12 changes: 6 additions & 6 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 2 additions & 3 deletions projects/app/i18n/zh/common.json
Original file line number Diff line number Diff line change
Expand Up @@ -644,8 +644,7 @@
"success": "开始同步"
}
},
"training": {
}
"training": {}
},
"data": {
"Auxiliary Data": "辅助数据",
Expand Down Expand Up @@ -920,7 +919,7 @@
"AppId": "应用的ID",
"ChatId": "当前对话ID",
"Current time": "当前时间",
"Histories": "历史记录,最多取10条",
"Histories": "最近10条聊天记录",
"Key already exists": "Key 已经存在",
"Key cannot be empty": "参数名不能为空",
"Props name": "参数名",
Expand Down
2 changes: 0 additions & 2 deletions projects/app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@
"nextjs-node-loader": "^1.1.5",
"nprogress": "^0.2.0",
"react": "18.2.0",
"react-beautiful-dnd": "^13.1.1",
"react-day-picker": "^8.7.1",
"react-dom": "18.2.0",
"react-hook-form": "7.43.1",
Expand All @@ -73,7 +72,6 @@
"@types/lodash": "^4.14.191",
"@types/node": "^20.8.5",
"@types/react": "18.2.0",
"@types/react-beautiful-dnd": "^13.1.8",
"@types/react-dom": "18.2.0",
"@types/react-syntax-highlighter": "^15.5.6",
"@types/request-ip": "^0.0.37",
Expand Down
22 changes: 17 additions & 5 deletions projects/app/src/components/ChatBox/components/VariableInput.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { VariableItemType } from '@fastgpt/global/core/app/type.d';
import React, { useState } from 'react';
import React, { useEffect, useState } from 'react';
import { UseFormReturn } from 'react-hook-form';
import { useTranslation } from 'next-i18next';
import { Box, Button, Card, Input, Textarea } from '@chakra-ui/react';
Expand All @@ -24,10 +24,23 @@ const VariableInput = ({
chatForm: UseFormReturn<ChatBoxInputFormType>;
}) => {
const { t } = useTranslation();
const [refresh, setRefresh] = useState(false);
const { register, setValue, handleSubmit: handleSubmitChat, watch } = chatForm;
const { register, unregister, setValue, handleSubmit: handleSubmitChat, watch } = chatForm;
const variables = watch('variables');

useEffect(() => {
// 重新注册所有字段
variableModules.forEach((item) => {
register(`variables.${item.key}`, { required: item.required });
});

return () => {
// 组件卸载时注销所有字段
variableModules.forEach((item) => {
unregister(`variables.${item.key}`);
});
};
}, [register, unregister, variableModules]);

return (
<Box py={3}>
{/* avatar */}
Expand Down Expand Up @@ -92,7 +105,6 @@ const VariableInput = ({
value={variables[item.key]}
onchange={(e) => {
setValue(`variables.${item.key}`, e);
setRefresh((state) => !state);
}}
/>
)}
Expand All @@ -116,4 +128,4 @@ const VariableInput = ({
);
};

export default React.memo(VariableInput);
export default VariableInput;
35 changes: 23 additions & 12 deletions projects/app/src/components/ChatBox/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -158,12 +158,6 @@ const ChatBox = (
isChatting
} = useChatProviderStore();

/* variable */
const filterVariableModules = useMemo(
() => variableModules.filter((item) => item.type !== VariableInputEnum.custom),
[variableModules]
);

// compute variable input is finish.
const chatForm = useForm<ChatBoxInputFormType>({
defaultValues: {
Expand All @@ -174,9 +168,15 @@ const ChatBox = (
}
});
const { setValue, watch, handleSubmit } = chatForm;
const variables = watch('variables');
const chatStarted = watch('chatStarted');
const variableIsFinish = useMemo(() => {

/* variable */
const variables = watch('variables');
const filterVariableModules = useMemo(
() => variableModules.filter((item) => item.type !== VariableInputEnum.custom),
[variableModules]
);
const variableIsFinish = (() => {
if (!filterVariableModules || filterVariableModules.length === 0 || chatHistories.length > 0)
return true;

Expand All @@ -188,7 +188,7 @@ const ChatBox = (
}

return chatStarted;
}, [filterVariableModules, chatHistories.length, chatStarted, variables]);
})();

// 滚动到底部
const scrollToBottom = (behavior: 'smooth' | 'auto' = 'smooth') => {
Expand Down Expand Up @@ -360,6 +360,12 @@ const ChatBox = (
[questionGuide, shareId, outLinkUid, teamId, teamToken]
);

/* Abort chat completions, questionGuide */
const abortRequest = useCallback(() => {
chatController.current?.abort('stop');
questionGuideController.current?.abort('stop');
}, []);

/**
* user confirm send prompt
*/
Expand All @@ -383,6 +389,8 @@ const ChatBox = (
return;
}

abortRequest();

text = text.trim();

if (!text && files.length === 0) {
Expand Down Expand Up @@ -472,7 +480,8 @@ const ChatBox = (
generatingMessage: (e) => generatingMessage({ ...e, autoTTSResponse }),
variables
});
setValue('variables', newVariables || []);

newVariables && setValue('variables', newVariables);

isNewChatReplace.current = isNewChat;

Expand Down Expand Up @@ -540,6 +549,7 @@ const ChatBox = (
})();
},
[
abortRequest,
chatHistories,
createQuestionGuide,
finishSegmentedAudio,
Expand Down Expand Up @@ -710,7 +720,7 @@ const ChatBox = (
});
};
},
[appId, chatId, feedbackType, teamId, teamToken]
[appId, chatId, feedbackType, setChatHistories, teamId, teamToken]
);
const onADdUserDislike = useCallback(
(chat: ChatSiteItemType) => {
Expand Down Expand Up @@ -747,7 +757,7 @@ const ChatBox = (
return () => setFeedbackId(chat.dataId);
}
},
[appId, chatId, feedbackType, outLinkUid, shareId, teamId, teamToken]
[appId, chatId, feedbackType, outLinkUid, setChatHistories, shareId, teamId, teamToken]
);
const onReadUserDislike = useCallback(
(chat: ChatSiteItemType) => {
Expand Down Expand Up @@ -868,6 +878,7 @@ const ChatBox = (
setValue('variables', e || defaultVal);
},
resetHistory(e) {
abortRequest();
setValue('chatStarted', e.length > 0);
setChatHistories(e);
},
Expand Down
Loading

0 comments on commit fef1a17

Please sign in to comment.