Skip to content

Commit

Permalink
perf: code (labring#3232)
Browse files Browse the repository at this point in the history
* perf: code

* update doc
  • Loading branch information
c121914yu authored and Jiangween committed Dec 1, 2024
1 parent 5e2d54d commit 476bfb0
Show file tree
Hide file tree
Showing 7 changed files with 37 additions and 40 deletions.
12 changes: 8 additions & 4 deletions docSite/content/zh-cn/docs/development/upgrading/4814.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,11 @@ weight: 810
1. 新增 - 工作流支持进入聊天框/点击开始对话后,自动触发一轮对话。
2. 新增 - 重写 chatContext,对话测试也会有日志,并且刷新后不会丢失对话。
3. 新增 - 分享链接支持配置是否允许查看原文。
4. 优化 - 工作流 ui 细节。
5. 优化 - 应用编辑记录采用 diff 存储,避免浏览器溢出。
6. 修复 - 分块策略,四级标题会被丢失。 同时新增了五级标题的支持。
7. 修复 - MongoDB 知识库集合唯一索引。
4. 新增 - 新的 doc2x 插件。
5. 优化 - 工作流 ui 细节。
6. 优化 - 应用编辑记录采用 diff 存储,避免浏览器溢出。
7. 修复 - 分块策略,四级标题会被丢失。 同时新增了五级标题的支持。
8. 修复 - MongoDB 知识库集合唯一索引。
9. 修复 - 反选知识库引用后可能会报错。
10. 修复 - 简易模式转工作流,不是使用最新编辑记录进行转移。
11. 修复 - 表单输入的说明文字不显示。
6 changes: 1 addition & 5 deletions packages/service/core/workflow/dispatch/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -129,11 +129,7 @@ export const valueTypeFormat = (value: any, type?: WorkflowIOValueTypeEnum) => {
return value;
};

export const checkQuoteQAValue = (quoteQA?: SearchDataResponseItemType[]) => {
if (!quoteQA) return undefined;
if (quoteQA.length === 0) {
return [];
}
export const checkQuoteQAValue = (quoteQA: SearchDataResponseItemType[] = []) => {
if (quoteQA.some((item) => !item.q || !item.datasetId)) {
return undefined;
}
Expand Down
7 changes: 5 additions & 2 deletions packages/web/components/common/MySelect/MultipleRowSelect.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,11 @@ export const MultipleRowSelect = ({
const newValue = [...cloneValue];

if (item.value === selectedValue) {
setCloneValue([undefined]);
onSelect(undefined);
for (let i = index; i < newValue.length; i++) {
newValue[i] = undefined;
}
setCloneValue(newValue);
onSelect(newValue);
} else {
newValue[index] = item.value;
setCloneValue(newValue);
Expand Down
2 changes: 1 addition & 1 deletion packages/web/components/common/MySelect/type.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export type MultipleSelectProps = {
list: ListItemType[];
emptyTip?: string;
maxH?: number;
onSelect: (val: any[] | undefined) => void;
onSelect: (val: any[]) => void;
styles?: ButtonProps;
popDirection?: 'top' | 'bottom';
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ type Props = OutLinkChatAuthProps &
};

const ChatBox = ({
isReady = true,
feedbackType = FeedbackTypeEnum.hidden,
showMarkIcon = false,
showVoiceIcon = true,
Expand Down Expand Up @@ -812,7 +813,7 @@ const ChatBox = ({
setQuestionGuide([]);
setValue('chatStarted', false);
abortRequest('leave');
}, [router.query, setValue, chatId, abortRequest]);
}, [router.query, setValue, chatId]);

// add listener
useEffect(() => {
Expand Down Expand Up @@ -857,6 +858,22 @@ const ChatBox = ({
}
}, [isReady, chatStarted, autoExecute?.open, chatRecords, isChatRecordsLoaded]);

// Auto send prompt
useEffect(() => {
if (
isReady &&
autoExecute.open &&
chatStarted &&
chatRecords.length === 0 &&
isChatRecordsLoaded
) {
sendPrompt({
text: autoExecute.defaultPrompt || 'AUTO_EXECUTE',
hideInUI: true
});
}
}, [isReady, chatStarted, autoExecute?.open, chatRecords, isChatRecordsLoaded]);

// output data
useImperativeHandle(ChatBoxRef, () => ({
restartChat() {
Expand All @@ -871,16 +888,6 @@ const ChatBox = ({
}
}));

// Auto send prompt
useEffect(() => {
if (autoExecute.open && chatStarted && chatRecords.length === 0 && isChatRecordsLoaded) {
sendPrompt({
text: autoExecute.defaultPrompt || 'AUTO_EXECUTE',
hideInUI: true
});
}
}, [sendPrompt, chatStarted, autoExecute, chatRecords, isChatRecordsLoaded]);

const RenderRecords = useMemo(() => {
return (
<ScrollData
Expand Down
20 changes: 3 additions & 17 deletions projects/app/src/pages/app/detail/components/SimpleApp/AppCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,7 @@ import MyMenu from '@fastgpt/web/components/common/MyMenu';
import MyModal from '@fastgpt/web/components/common/MyModal';
import { useRequest2 } from '@fastgpt/web/hooks/useRequest';
import { postTransition2Workflow } from '@/web/core/app/api/app';
import { AppTypeEnum } from '@fastgpt/global/core/app/constants';
import { form2AppWorkflow } from '@/web/core/app/utils';
import { formatTime2YMDHMS } from '@fastgpt/global/common/string/time';
import { SimpleAppSnapshotType } from './useSnapshots';

const AppCard = ({
Expand All @@ -38,7 +36,6 @@ const AppCard = ({
const { t } = useTranslation();
const onSaveApp = useContextSelector(AppContext, (v) => v.onSaveApp);
const appDetail = useContextSelector(AppContext, (v) => v.appDetail);
const setAppDetail = useContextSelector(AppContext, (v) => v.setAppDetail);
const onOpenInfoEdit = useContextSelector(AppContext, (v) => v.onOpenInfoEdit);
const onDelApp = useContextSelector(AppContext, (v) => v.onDelApp);

Expand All @@ -55,22 +52,11 @@ const AppCard = ({
nodes,
edges,
chatConfig: appForm.chatConfig,
type: AppTypeEnum.simple,
isPublish: true,
versionName: formatTime2YMDHMS(new Date())
isPublish: false,
versionName: t('app:transition_to_workflow')
});
setPast((prevPast) =>
prevPast.map((item, index) =>
index === 0
? {
...item,
isSaved: true
}
: item
)
);

return await postTransition2Workflow({ appId, createNew: transitionCreateNew });
return postTransition2Workflow({ appId, createNew: transitionCreateNew });
},
{
onSuccess: ({ id }) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ export const useChatTest = ({
</Box>
) : (
<ChatBox
isReady={isReady}
appId={appId}
chatId={chatId}
showMarkIcon
Expand Down

0 comments on commit 476bfb0

Please sign in to comment.