Skip to content

Commit

Permalink
Perf workflow (#1492)
Browse files Browse the repository at this point in the history
* perf: handle edge check

* search model

* feat: plugin input can render all input; fix: plugin default value

* fix ts

* feat: plugin input support required
  • Loading branch information
c121914yu authored May 15, 2024
1 parent cd87625 commit 8386f70
Show file tree
Hide file tree
Showing 36 changed files with 256 additions and 160 deletions.
1 change: 1 addition & 0 deletions .vscode/i18n-ally-custom-framework.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ usageMatchRegex:
- "[^\\w\\d]datasetT\\(['\"`]({key})['\"`]"
- "[^\\w\\d]fileT\\(['\"`]({key})['\"`]"
- "[^\\w\\d]publishT\\(['\"`]({key})['\"`]"
- "[^\\w\\d]workflowT\\(['\"`]({key})['\"`]"

# A RegEx to set a custom scope range. This scope will be used as a prefix when detecting keys
# and works like how the i18next framework identifies the namespace scope from the
Expand Down
2 changes: 1 addition & 1 deletion docSite/content/docs/development/openapi/share.md
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ curl --location --request POST '{{host}}/shareAuth/finish' \

```ts
type ResponseType = {
moduleType: `${FlowNodeTypeEnum}`; // 模块类型
moduleType: FlowNodeTypeEnum; // 模块类型
moduleName: string; // 模块名
moduleLogo?: string; // logo
runningTime?: number; // 运行时间
Expand Down
7 changes: 5 additions & 2 deletions docSite/content/docs/development/upgrading/481.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,5 +35,8 @@ curl --location --request POST 'https://{{host}}/api/admin/clearInvalidData' \
## V4.8.1 更新说明

1. 新增 - 知识库重新选择向量模型重建
2. 修复 - 工作流删除节点的动态输入和输出时候,没有正确的删除连接线,导致可能出现逻辑异常。
3. 修复 - 定时器清理脏数据任务
2. 新增 - 工作流节点版本变更提示,并可以同步最新版本。
3. 优化 - 插件输入的 debug 模式,支持全量参数输入渲染。
4. 修复 - 插件输入默认值被清空问题。
5. 修复 - 工作流删除节点的动态输入和输出时候,没有正确的删除连接线,导致可能出现逻辑异常。
6. 修复 - 定时器清理脏数据任务
2 changes: 1 addition & 1 deletion packages/global/core/chat/type.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ export type ChatHistoryItemType = HistoryItemType & {
/* ------- response data ------------ */
export type ChatHistoryItemResType = DispatchNodeResponseType & {
nodeId: string;
moduleType: `${FlowNodeTypeEnum}`;
moduleType: FlowNodeTypeEnum;
moduleName: string;
};

Expand Down
2 changes: 1 addition & 1 deletion packages/global/core/workflow/api.d.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { VectorModelItemType } from '../ai/model.d';
import { NodeInputKeyEnum } from './constants';

export type SelectedDatasetType = { datasetId: string; vectorModel: VectorModelItemType }[];
export type SelectedDatasetType = { datasetId: string }[];

export type HttpBodyType<T = Record<string, any>> = {
[NodeInputKeyEnum.addInputParam]: Record<string, any>;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ export const DatasetSearchModule: FlowNodeTemplateType = {
label: 'core.module.input.label.Select dataset',
value: [],
valueType: WorkflowIOValueTypeEnum.selectDataset,
list: [],
required: true
},
{
Expand Down
2 changes: 1 addition & 1 deletion packages/global/core/workflow/type/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import { RuntimeEdgeItemType, StoreEdgeItemType } from './edge';
import { NextApiResponse } from 'next';

export type FlowNodeCommonType = {
flowNodeType: `${FlowNodeTypeEnum}`; // render node card
flowNodeType: FlowNodeTypeEnum; // render node card

avatar?: string;
name: string;
Expand Down
12 changes: 3 additions & 9 deletions packages/global/core/workflow/utils.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { FlowNodeOutputTypeEnum, FlowNodeTypeEnum } from './node/constant';
import { FlowNodeInputTypeEnum, FlowNodeOutputTypeEnum, FlowNodeTypeEnum } from './node/constant';
import {
WorkflowIOValueTypeEnum,
NodeInputKeyEnum,
Expand All @@ -22,15 +22,9 @@ export const getHandleId = (nodeId: string, type: 'source' | 'target', key: stri
};

export const checkInputIsReference = (input: FlowNodeInputItemType) => {
const value = input.value;
if (
Array.isArray(value) &&
value.length === 2 &&
typeof value[0] === 'string' &&
typeof value[1] === 'string'
) {
if (input.renderTypeList?.[input?.selectedTypeIndex || 0] === FlowNodeInputTypeEnum.reference)
return true;
}

return false;
};

Expand Down
5 changes: 4 additions & 1 deletion packages/service/core/workflow/dispatch/dataset/search.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import { getHistories } from '../utils';
import { datasetSearchQueryExtension } from '../../../dataset/search/utils';
import { ChatNodeUsageType } from '@fastgpt/global/support/wallet/bill/type';
import { checkTeamReRankPermission } from '../../../../support/permission/teamLimit';
import { MongoDataset } from '../../../dataset/schema';

type DatasetSearchProps = ModuleDispatchProps<{
[NodeInputKeyEnum.datasetSelectList]: SelectedDatasetType;
Expand Down Expand Up @@ -79,7 +80,9 @@ export async function dispatchDatasetSearch(
// console.log(concatQueries, rewriteQuery, aiExtensionResult);

// get vector
const vectorModel = getVectorModel(datasets[0]?.vectorModel?.model);
const vectorModel = getVectorModel(
(await MongoDataset.findById(datasets[0].datasetId, 'vectorModel').lean())?.vectorModel
);

// start search
const {
Expand Down
2 changes: 1 addition & 1 deletion packages/service/core/workflow/dispatch/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ import { getReferenceVariableValue } from '@fastgpt/global/core/workflow/runtime
import { dispatchSystemConfig } from './init/systemConfig';
import { dispatchUpdateVariable } from './tools/runUpdateVar';

const callbackMap: Record<`${FlowNodeTypeEnum}`, Function> = {
const callbackMap: Record<FlowNodeTypeEnum, Function> = {
[FlowNodeTypeEnum.workflowStart]: dispatchWorkflowStart,
[FlowNodeTypeEnum.answerNode]: dispatchAnswer,
[FlowNodeTypeEnum.chatNode]: dispatchChatCompletion,
Expand Down
36 changes: 36 additions & 0 deletions packages/web/components/common/Input/NumberInput/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import {
NumberInput,
NumberIncrementStepper,
NumberInputField,
NumberInputStepper,
NumberDecrementStepper,
NumberInputProps
} from '@chakra-ui/react';
import React from 'react';

type Props = Omit<NumberInputProps, 'onChange'> & {
onChange: (e: number | '') => any;
};

const MyNumberInput = (props: Props) => {
return (
<NumberInput
{...props}
onChange={(e) => {
if (isNaN(Number(e))) {
props?.onChange('');
} else {
props?.onChange(Number(e));
}
}}
>
<NumberInputField />
<NumberInputStepper>
<NumberIncrementStepper />
<NumberDecrementStepper />
</NumberInputStepper>
</NumberInput>
);
};

export default MyNumberInput;
2 changes: 1 addition & 1 deletion packages/web/components/common/MyDrawer/MyRightDrawer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ const MyRightDrawer = ({
<DrawerCloseButton position={'relative'} fontSize={'sm'} top={0} right={0} />
</Flex>

<DrawerBody>
<DrawerBody overflow={'unset'} px={props?.px}>
{children}
<Loading loading={isLoading} fixed={false} />
</DrawerBody>
Expand Down
2 changes: 1 addition & 1 deletion projects/app/i18n/en/dataset.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"Common Dataset": "Common dataset",
"Common Dataset Desc": "Can be built by importing files, web links, or manual entry",
"Confirm to rebuild embedding tip": "Are you sure to switch the knowledge base index? Switching index is a very heavy operation that requires re-indexing all the data in your knowledge base, which may take a long time. Please ensure that the remaining points in your account are sufficient.",
"Confirm to rebuild embedding tip": "Are you sure to switch the knowledge base index?\nSwitching index is a very heavy operation that requires re-indexing all the data in your knowledge base, which may take a long time. Please ensure that the remaining points in your account are sufficient.\n\nIn addition, you need to be careful to modify the applications that select this knowledge base to avoid mixing them with other index model knowledge bases.",
"External file": "External file",
"External file Dataset Desc": "You can import files from an external file library to build a knowledge base. Files are not stored twice",
"External id": "File id",
Expand Down
3 changes: 3 additions & 0 deletions projects/app/i18n/en/workflow.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"Field required": "Required"
}
2 changes: 1 addition & 1 deletion projects/app/i18n/zh/dataset.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"Common Dataset": "通用知识库",
"Common Dataset Desc": "可通过导入文件、网页链接或手动录入形式构建知识库",
"Confirm to rebuild embedding tip": "确认为知识库切换索引?\n切换索引是一个非常重量的操作,需要对您知识库内所有数据进行重新索引,时间可能较长,请确保账号内剩余积分充足。",
"Confirm to rebuild embedding tip": "确认为知识库切换索引?\n切换索引是一个非常重量的操作,需要对您知识库内所有数据进行重新索引,时间可能较长,请确保账号内剩余积分充足。\n\n此外,你还需要注意修改选择该知识库的应用,避免它们与其他索引模型知识库混用。",
"External File": "外部文件库",
"External file Dataset Desc": "可以从外部文件库导入文件构建知识库,文件不会进行二次存储",
"External id": "文件阅读ID",
Expand Down
3 changes: 3 additions & 0 deletions projects/app/i18n/zh/workflow.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"Field required": "必填"
}
11 changes: 5 additions & 6 deletions projects/app/src/components/core/app/DatasetSelectModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ export const DatasetSelectModal = ({
_hover={{ color: 'red.500' }}
onClick={() => {
setSelectedDatasets((state) =>
state.filter((kb) => kb.datasetId !== item._id)
state.filter((dataset) => dataset.datasetId !== item._id)
);
}}
/>
Expand Down Expand Up @@ -141,18 +141,17 @@ export const DatasetSelectModal = ({
if (item.type === DatasetTypeEnum.folder) {
setParentId(item._id);
} else {
const vectorModel = selectedDatasets[0]?.vectorModel?.model;
const vectorModel = datasets.find(
(dataset) => dataset._id === selectedDatasets[0]?.datasetId
)?.vectorModel?.model;

if (vectorModel && vectorModel !== item.vectorModel.model) {
return toast({
status: 'warning',
title: t('dataset.Select Dataset Tips')
});
}
setSelectedDatasets((state) => [
...state,
{ datasetId: item._id, vectorModel: item.vectorModel }
]);
setSelectedDatasets((state) => [...state, { datasetId: item._id }]);
}
}}
>
Expand Down
Loading

0 comments on commit 8386f70

Please sign in to comment.