balibabu
commited on
Commit
·
b2b0160
1
Parent(s):
4856f42
feat: add description text to operators and extract the useFetchModelId to logicHooks.ts and drag the operator to the canvas and initialize the form data #918 (#1379)
Browse files### What problem does this PR solve?
feat: add description text to operators #918
feat: drag the operator to the canvas and initialize the form data #918
feat: extract the useFetchModelId to logicHooks.ts
### Type of change
- [x] New Feature (non-breaking change which adds functionality)
- web/.umirc.ts +40 -40
- web/src/components/message-item/index.less +2 -2
- web/src/hooks/logicHooks.ts +29 -1
- web/src/locales/en.ts +11 -0
- web/src/pages/chat/chat-configuration-modal/hooks.ts +0 -29
- web/src/pages/chat/chat-configuration-modal/index.tsx +1 -1
- web/src/pages/flow/chat/drawer.tsx +5 -2
- web/src/pages/flow/constant.tsx +20 -3
- web/src/pages/flow/flow-sider/index.tsx +7 -11
- web/src/pages/flow/hooks.ts +46 -3
- web/src/pages/flow/list/index.less +1 -1
- web/src/pages/flow/utils.ts +9 -9
web/.umirc.ts
CHANGED
|
@@ -1,40 +1,40 @@
|
|
| 1 |
-
import { defineConfig } from 'umi';
|
| 2 |
-
import { appName } from './src/conf.json';
|
| 3 |
-
import routes from './src/routes';
|
| 4 |
-
|
| 5 |
-
export default defineConfig({
|
| 6 |
-
title: appName,
|
| 7 |
-
outputPath: 'dist',
|
| 8 |
-
// alias: { '@': './src' },
|
| 9 |
-
npmClient: 'npm',
|
| 10 |
-
base: '/',
|
| 11 |
-
routes,
|
| 12 |
-
publicPath: '/',
|
| 13 |
-
esbuildMinifyIIFE: true,
|
| 14 |
-
icons: {},
|
| 15 |
-
hash: true,
|
| 16 |
-
favicons: ['/logo.svg'],
|
| 17 |
-
clickToComponent: {},
|
| 18 |
-
history: {
|
| 19 |
-
type: 'browser',
|
| 20 |
-
},
|
| 21 |
-
plugins: ['@react-dev-inspector/umi4-plugin', '@umijs/plugins/dist/dva'],
|
| 22 |
-
dva: {},
|
| 23 |
-
|
| 24 |
-
lessLoader: {
|
| 25 |
-
modifyVars: {
|
| 26 |
-
hack: `true; @import "~@/less/index.less";`,
|
| 27 |
-
},
|
| 28 |
-
},
|
| 29 |
-
devtool: 'source-map',
|
| 30 |
-
copy: ['src/conf.json'],
|
| 31 |
-
proxy: {
|
| 32 |
-
'/v1': {
|
| 33 |
-
target: '',
|
| 34 |
-
changeOrigin: true,
|
| 35 |
-
ws: true,
|
| 36 |
-
logger: console,
|
| 37 |
-
// pathRewrite: { '^/v1': '/v1' },
|
| 38 |
-
},
|
| 39 |
-
},
|
| 40 |
-
});
|
|
|
|
| 1 |
+
import { defineConfig } from 'umi';
|
| 2 |
+
import { appName } from './src/conf.json';
|
| 3 |
+
import routes from './src/routes';
|
| 4 |
+
|
| 5 |
+
export default defineConfig({
|
| 6 |
+
title: appName,
|
| 7 |
+
outputPath: 'dist',
|
| 8 |
+
// alias: { '@': './src' },
|
| 9 |
+
npmClient: 'npm',
|
| 10 |
+
base: '/',
|
| 11 |
+
routes,
|
| 12 |
+
publicPath: '/',
|
| 13 |
+
esbuildMinifyIIFE: true,
|
| 14 |
+
icons: {},
|
| 15 |
+
hash: true,
|
| 16 |
+
favicons: ['/logo.svg'],
|
| 17 |
+
clickToComponent: {},
|
| 18 |
+
history: {
|
| 19 |
+
type: 'browser',
|
| 20 |
+
},
|
| 21 |
+
plugins: ['@react-dev-inspector/umi4-plugin', '@umijs/plugins/dist/dva'],
|
| 22 |
+
dva: {},
|
| 23 |
+
|
| 24 |
+
lessLoader: {
|
| 25 |
+
modifyVars: {
|
| 26 |
+
hack: `true; @import "~@/less/index.less";`,
|
| 27 |
+
},
|
| 28 |
+
},
|
| 29 |
+
devtool: 'source-map',
|
| 30 |
+
copy: ['src/conf.json'],
|
| 31 |
+
proxy: {
|
| 32 |
+
'/v1': {
|
| 33 |
+
target: '',
|
| 34 |
+
changeOrigin: true,
|
| 35 |
+
ws: true,
|
| 36 |
+
logger: console,
|
| 37 |
+
// pathRewrite: { '^/v1': '/v1' },
|
| 38 |
+
},
|
| 39 |
+
},
|
| 40 |
+
});
|
web/src/components/message-item/index.less
CHANGED
|
@@ -4,10 +4,10 @@
|
|
| 4 |
display: inline-block;
|
| 5 |
}
|
| 6 |
.messageItemSectionLeft {
|
| 7 |
-
width:
|
| 8 |
}
|
| 9 |
.messageItemSectionRight {
|
| 10 |
-
width:
|
| 11 |
}
|
| 12 |
.messageItemContent {
|
| 13 |
display: inline-flex;
|
|
|
|
| 4 |
display: inline-block;
|
| 5 |
}
|
| 6 |
.messageItemSectionLeft {
|
| 7 |
+
width: 80%;
|
| 8 |
}
|
| 9 |
.messageItemSectionRight {
|
| 10 |
+
width: 80%;
|
| 11 |
}
|
| 12 |
.messageItemContent {
|
| 13 |
display: inline-flex;
|
web/src/hooks/logicHooks.ts
CHANGED
|
@@ -22,8 +22,13 @@ import { useTranslation } from 'react-i18next';
|
|
| 22 |
import { useDispatch } from 'umi';
|
| 23 |
import { useSetModalState, useTranslate } from './commonHooks';
|
| 24 |
import { useSetDocumentParser } from './documentHooks';
|
|
|
|
| 25 |
import { useOneNamespaceEffectsLoading } from './storeHooks';
|
| 26 |
-
import {
|
|
|
|
|
|
|
|
|
|
|
|
|
| 27 |
|
| 28 |
export const useChangeDocumentParser = (documentId: string) => {
|
| 29 |
const setDocumentParser = useSetDocumentParser();
|
|
@@ -269,3 +274,26 @@ export const useSelectItem = (defaultId?: string) => {
|
|
| 269 |
|
| 270 |
return { selectedId, handleItemClick };
|
| 271 |
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 22 |
import { useDispatch } from 'umi';
|
| 23 |
import { useSetModalState, useTranslate } from './commonHooks';
|
| 24 |
import { useSetDocumentParser } from './documentHooks';
|
| 25 |
+
import { useFetchLlmList } from './llmHooks';
|
| 26 |
import { useOneNamespaceEffectsLoading } from './storeHooks';
|
| 27 |
+
import {
|
| 28 |
+
useFetchTenantInfo,
|
| 29 |
+
useSaveSetting,
|
| 30 |
+
useSelectTenantInfo,
|
| 31 |
+
} from './userSettingHook';
|
| 32 |
|
| 33 |
export const useChangeDocumentParser = (documentId: string) => {
|
| 34 |
const setDocumentParser = useSetDocumentParser();
|
|
|
|
| 274 |
|
| 275 |
return { selectedId, handleItemClick };
|
| 276 |
};
|
| 277 |
+
|
| 278 |
+
export const useFetchModelId = (visible: boolean) => {
|
| 279 |
+
const fetchTenantInfo = useFetchTenantInfo(false);
|
| 280 |
+
const tenantInfo = useSelectTenantInfo();
|
| 281 |
+
|
| 282 |
+
useEffect(() => {
|
| 283 |
+
if (visible) {
|
| 284 |
+
fetchTenantInfo();
|
| 285 |
+
}
|
| 286 |
+
}, [visible, fetchTenantInfo]);
|
| 287 |
+
|
| 288 |
+
return tenantInfo?.llm_id ?? '';
|
| 289 |
+
};
|
| 290 |
+
|
| 291 |
+
export const useFetchLlmModelOnVisible = (visible: boolean) => {
|
| 292 |
+
const fetchLlmList = useFetchLlmList();
|
| 293 |
+
|
| 294 |
+
useEffect(() => {
|
| 295 |
+
if (visible) {
|
| 296 |
+
fetchLlmList();
|
| 297 |
+
}
|
| 298 |
+
}, [fetchLlmList, visible]);
|
| 299 |
+
};
|
web/src/locales/en.ts
CHANGED
|
@@ -565,6 +565,17 @@ The above is the content you need to summarize.`,
|
|
| 565 |
componentId: 'component id',
|
| 566 |
add: 'Add',
|
| 567 |
operation: 'operation',
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 568 |
},
|
| 569 |
footer: {
|
| 570 |
profile: 'All rights reserved @ React',
|
|
|
|
| 565 |
componentId: 'component id',
|
| 566 |
add: 'Add',
|
| 567 |
operation: 'operation',
|
| 568 |
+
beginDescription: 'This is where the flow begin',
|
| 569 |
+
answerDescription: `This component is used as an interface between bot and human. It receives input of user and display the result of the computation of the bot.`,
|
| 570 |
+
retrievalDescription: `This component is for the process of retrieving relevent information from knowledge base. So, knowledgebases should be selected. If there's nothing retrieved, the 'Empty response' will be returned.`,
|
| 571 |
+
generateDescription: `This component is used to call LLM to generate text. Be careful about the prompt setting.`,
|
| 572 |
+
categorizeDescription: `This component is used to categorize text. Please specify the name, description and examples of the category. Every single category leads to different downstream components.`,
|
| 573 |
+
relevantDescription: `This component is used to judge if the retrieved information is relevent to user's question. 'Yes' represents that they're relevant. 'No' represents they're irrelevant.`,
|
| 574 |
+
rewriteQuestionDescription: `This component is used to refine user's quesion. Typically, when a user's original question can't retrieve relevant information from knowledge base, this component help you change the question into a proper one which might be more consistant with the expressions in knowledge base. Only 'Retrieval' can be its downstreams.`,
|
| 575 |
+
messageDescription:
|
| 576 |
+
'This component is used to send user static information.',
|
| 577 |
+
keywordDescription:
|
| 578 |
+
'This component is used to send user static information.',
|
| 579 |
},
|
| 580 |
footer: {
|
| 581 |
profile: 'All rights reserved @ React',
|
web/src/pages/chat/chat-configuration-modal/hooks.ts
DELETED
|
@@ -1,29 +0,0 @@
|
|
| 1 |
-
import { useFetchLlmList } from '@/hooks/llmHooks';
|
| 2 |
-
import {
|
| 3 |
-
useFetchTenantInfo,
|
| 4 |
-
useSelectTenantInfo,
|
| 5 |
-
} from '@/hooks/userSettingHook';
|
| 6 |
-
import { useEffect } from 'react';
|
| 7 |
-
|
| 8 |
-
export const useFetchModelId = (visible: boolean) => {
|
| 9 |
-
const fetchTenantInfo = useFetchTenantInfo(false);
|
| 10 |
-
const tenantInfo = useSelectTenantInfo();
|
| 11 |
-
|
| 12 |
-
useEffect(() => {
|
| 13 |
-
if (visible) {
|
| 14 |
-
fetchTenantInfo();
|
| 15 |
-
}
|
| 16 |
-
}, [visible, fetchTenantInfo]);
|
| 17 |
-
|
| 18 |
-
return tenantInfo?.llm_id ?? '';
|
| 19 |
-
};
|
| 20 |
-
|
| 21 |
-
export const useFetchLlmModelOnVisible = (visible: boolean) => {
|
| 22 |
-
const fetchLlmList = useFetchLlmList();
|
| 23 |
-
|
| 24 |
-
useEffect(() => {
|
| 25 |
-
if (visible) {
|
| 26 |
-
fetchLlmList();
|
| 27 |
-
}
|
| 28 |
-
}, [fetchLlmList, visible]);
|
| 29 |
-
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
web/src/pages/chat/chat-configuration-modal/index.tsx
CHANGED
|
@@ -11,11 +11,11 @@ import camelCase from 'lodash/camelCase';
|
|
| 11 |
import { useEffect, useRef, useState } from 'react';
|
| 12 |
import { IPromptConfigParameters } from '../interface';
|
| 13 |
import AssistantSetting from './assistant-setting';
|
| 14 |
-
import { useFetchLlmModelOnVisible, useFetchModelId } from './hooks';
|
| 15 |
import ModelSetting from './model-setting';
|
| 16 |
import PromptEngine from './prompt-engine';
|
| 17 |
|
| 18 |
import { useTranslate } from '@/hooks/commonHooks';
|
|
|
|
| 19 |
import { getBase64FromUploadFileList } from '@/utils/fileUtil';
|
| 20 |
import { removeUselessFieldsFromValues } from '@/utils/form';
|
| 21 |
import styles from './index.less';
|
|
|
|
| 11 |
import { useEffect, useRef, useState } from 'react';
|
| 12 |
import { IPromptConfigParameters } from '../interface';
|
| 13 |
import AssistantSetting from './assistant-setting';
|
|
|
|
| 14 |
import ModelSetting from './model-setting';
|
| 15 |
import PromptEngine from './prompt-engine';
|
| 16 |
|
| 17 |
import { useTranslate } from '@/hooks/commonHooks';
|
| 18 |
+
import { useFetchLlmModelOnVisible, useFetchModelId } from '@/hooks/logicHooks';
|
| 19 |
import { getBase64FromUploadFileList } from '@/utils/fileUtil';
|
| 20 |
import { removeUselessFieldsFromValues } from '@/utils/form';
|
| 21 |
import styles from './index.less';
|
web/src/pages/flow/chat/drawer.tsx
CHANGED
|
@@ -1,16 +1,19 @@
|
|
|
|
|
| 1 |
import { IModalProps } from '@/interfaces/common';
|
| 2 |
import { Drawer } from 'antd';
|
| 3 |
import FlowChatBox from './box';
|
| 4 |
|
| 5 |
const ChatDrawer = ({ visible, hideModal }: IModalProps<any>) => {
|
|
|
|
|
|
|
| 6 |
return (
|
| 7 |
<Drawer
|
| 8 |
-
title=
|
| 9 |
placement="right"
|
| 10 |
onClose={hideModal}
|
| 11 |
open={visible}
|
| 12 |
getContainer={false}
|
| 13 |
-
width={window.innerWidth > 1278 ? '
|
| 14 |
mask={false}
|
| 15 |
// zIndex={10000}
|
| 16 |
>
|
|
|
|
| 1 |
+
import { useFetchFlow } from '@/hooks/flow-hooks';
|
| 2 |
import { IModalProps } from '@/interfaces/common';
|
| 3 |
import { Drawer } from 'antd';
|
| 4 |
import FlowChatBox from './box';
|
| 5 |
|
| 6 |
const ChatDrawer = ({ visible, hideModal }: IModalProps<any>) => {
|
| 7 |
+
const { data } = useFetchFlow();
|
| 8 |
+
|
| 9 |
return (
|
| 10 |
<Drawer
|
| 11 |
+
title={data.title}
|
| 12 |
placement="right"
|
| 13 |
onClose={hideModal}
|
| 14 |
open={visible}
|
| 15 |
getContainer={false}
|
| 16 |
+
width={window.innerWidth > 1278 ? '40%' : 470}
|
| 17 |
mask={false}
|
| 18 |
// zIndex={10000}
|
| 19 |
>
|
web/src/pages/flow/constant.tsx
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
|
|
| 1 |
import {
|
| 2 |
BranchesOutlined,
|
| 3 |
DatabaseOutlined,
|
|
@@ -33,7 +34,7 @@ export const operatorIconMap = {
|
|
| 33 |
|
| 34 |
export const operatorMap = {
|
| 35 |
[Operator.Retrieval]: {
|
| 36 |
-
description: '
|
| 37 |
backgroundColor: '#cad6e0',
|
| 38 |
color: '#385974',
|
| 39 |
},
|
|
@@ -47,7 +48,8 @@ export const operatorMap = {
|
|
| 47 |
color: '#996464',
|
| 48 |
},
|
| 49 |
[Operator.Answer]: {
|
| 50 |
-
description:
|
|
|
|
| 51 |
backgroundColor: '#f4816d',
|
| 52 |
color: 'white',
|
| 53 |
},
|
|
@@ -126,7 +128,15 @@ export const initialBeginValues = {
|
|
| 126 |
prologue: `Hi! I'm your assistant, what can I do for you?`,
|
| 127 |
};
|
| 128 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 129 |
const initialLlmBaseValues = {
|
|
|
|
| 130 |
temperature: 0.1,
|
| 131 |
top_p: 0.3,
|
| 132 |
frequency_penalty: 0.7,
|
|
@@ -196,7 +206,14 @@ export const RestrictedUpstreamMap = {
|
|
| 196 |
[Operator.Answer]: [],
|
| 197 |
[Operator.Retrieval]: [],
|
| 198 |
[Operator.Generate]: [],
|
| 199 |
-
[Operator.Message]: [
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 200 |
[Operator.Relevant]: [],
|
| 201 |
[Operator.RewriteQuestion]: [],
|
| 202 |
};
|
|
|
|
| 1 |
+
import { variableEnabledFieldMap } from '@/constants/chat';
|
| 2 |
import {
|
| 3 |
BranchesOutlined,
|
| 4 |
DatabaseOutlined,
|
|
|
|
| 34 |
|
| 35 |
export const operatorMap = {
|
| 36 |
[Operator.Retrieval]: {
|
| 37 |
+
description: 'This is where the flow begin',
|
| 38 |
backgroundColor: '#cad6e0',
|
| 39 |
color: '#385974',
|
| 40 |
},
|
|
|
|
| 48 |
color: '#996464',
|
| 49 |
},
|
| 50 |
[Operator.Answer]: {
|
| 51 |
+
description:
|
| 52 |
+
'This component is used as an interface between bot and human. It receives input of user and display the result of the computation of the bot.',
|
| 53 |
backgroundColor: '#f4816d',
|
| 54 |
color: 'white',
|
| 55 |
},
|
|
|
|
| 128 |
prologue: `Hi! I'm your assistant, what can I do for you?`,
|
| 129 |
};
|
| 130 |
|
| 131 |
+
export const variableCheckBoxFieldMap = Object.keys(
|
| 132 |
+
variableEnabledFieldMap,
|
| 133 |
+
).reduce<Record<string, boolean>>((pre, cur) => {
|
| 134 |
+
pre[cur] = true;
|
| 135 |
+
return pre;
|
| 136 |
+
}, {});
|
| 137 |
+
|
| 138 |
const initialLlmBaseValues = {
|
| 139 |
+
...variableCheckBoxFieldMap,
|
| 140 |
temperature: 0.1,
|
| 141 |
top_p: 0.3,
|
| 142 |
frequency_penalty: 0.7,
|
|
|
|
| 206 |
[Operator.Answer]: [],
|
| 207 |
[Operator.Retrieval]: [],
|
| 208 |
[Operator.Generate]: [],
|
| 209 |
+
[Operator.Message]: [
|
| 210 |
+
Operator.Begin,
|
| 211 |
+
Operator.Message,
|
| 212 |
+
Operator.Generate,
|
| 213 |
+
Operator.Retrieval,
|
| 214 |
+
Operator.RewriteQuestion,
|
| 215 |
+
Operator.Categorize,
|
| 216 |
+
],
|
| 217 |
[Operator.Relevant]: [],
|
| 218 |
[Operator.RewriteQuestion]: [],
|
| 219 |
};
|
web/src/pages/flow/flow-sider/index.tsx
CHANGED
|
@@ -1,6 +1,7 @@
|
|
| 1 |
-
import {
|
|
|
|
| 2 |
import classNames from 'classnames';
|
| 3 |
-
|
| 4 |
import { componentMenuList } from '../constant';
|
| 5 |
import { useHandleDrag } from '../hooks';
|
| 6 |
import OperatorIcon from '../operator-icon';
|
|
@@ -8,8 +9,6 @@ import styles from './index.less';
|
|
| 8 |
|
| 9 |
const { Sider } = Layout;
|
| 10 |
|
| 11 |
-
const { Text } = Typography;
|
| 12 |
-
|
| 13 |
interface IProps {
|
| 14 |
setCollapsed: (width: boolean) => void;
|
| 15 |
collapsed: boolean;
|
|
@@ -17,6 +16,7 @@ interface IProps {
|
|
| 17 |
|
| 18 |
const FlowSide = ({ setCollapsed, collapsed }: IProps) => {
|
| 19 |
const { handleDragStart } = useHandleDrag();
|
|
|
|
| 20 |
|
| 21 |
return (
|
| 22 |
<Sider
|
|
@@ -40,13 +40,9 @@ const FlowSide = ({ setCollapsed, collapsed }: IProps) => {
|
|
| 40 |
<Space size={15}>
|
| 41 |
<OperatorIcon name={x.name}></OperatorIcon>
|
| 42 |
<section>
|
| 43 |
-
<
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
style={{ width: 130 }}
|
| 47 |
-
>
|
| 48 |
-
{x.description}
|
| 49 |
-
</Text>
|
| 50 |
</section>
|
| 51 |
</Space>
|
| 52 |
</Flex>
|
|
|
|
| 1 |
+
import { useTranslate } from '@/hooks/commonHooks';
|
| 2 |
+
import { Card, Flex, Layout, Space, Tooltip } from 'antd';
|
| 3 |
import classNames from 'classnames';
|
| 4 |
+
import lowerFirst from 'lodash/lowerFirst';
|
| 5 |
import { componentMenuList } from '../constant';
|
| 6 |
import { useHandleDrag } from '../hooks';
|
| 7 |
import OperatorIcon from '../operator-icon';
|
|
|
|
| 9 |
|
| 10 |
const { Sider } = Layout;
|
| 11 |
|
|
|
|
|
|
|
| 12 |
interface IProps {
|
| 13 |
setCollapsed: (width: boolean) => void;
|
| 14 |
collapsed: boolean;
|
|
|
|
| 16 |
|
| 17 |
const FlowSide = ({ setCollapsed, collapsed }: IProps) => {
|
| 18 |
const { handleDragStart } = useHandleDrag();
|
| 19 |
+
const { t } = useTranslate('flow');
|
| 20 |
|
| 21 |
return (
|
| 22 |
<Sider
|
|
|
|
| 40 |
<Space size={15}>
|
| 41 |
<OperatorIcon name={x.name}></OperatorIcon>
|
| 42 |
<section>
|
| 43 |
+
<Tooltip title={t(`${lowerFirst(x.name)}Description`)}>
|
| 44 |
+
<b>{x.name}</b>
|
| 45 |
+
</Tooltip>
|
|
|
|
|
|
|
|
|
|
|
|
|
| 46 |
</section>
|
| 47 |
</Space>
|
| 48 |
</Flex>
|
web/src/pages/flow/hooks.ts
CHANGED
|
@@ -17,13 +17,25 @@ import {
|
|
| 17 |
ModelVariableType,
|
| 18 |
settledModelVariableMap,
|
| 19 |
} from '@/constants/knowledge';
|
|
|
|
| 20 |
import { Variable } from '@/interfaces/database/chat';
|
| 21 |
import { useDebounceEffect } from 'ahooks';
|
| 22 |
import { FormInstance, message } from 'antd';
|
| 23 |
import { humanId } from 'human-id';
|
| 24 |
import trim from 'lodash/trim';
|
| 25 |
import { useParams } from 'umi';
|
| 26 |
-
import {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 27 |
import useGraphStore, { RFState } from './store';
|
| 28 |
import { buildDslComponentsByGraph } from './utils';
|
| 29 |
|
|
@@ -43,6 +55,32 @@ export const useSelectCanvasData = () => {
|
|
| 43 |
return useGraphStore(selector);
|
| 44 |
};
|
| 45 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 46 |
export const useHandleDrag = () => {
|
| 47 |
const handleDragStart = useCallback(
|
| 48 |
(operatorId: string) => (ev: React.DragEvent<HTMLDivElement>) => {
|
|
@@ -59,6 +97,7 @@ export const useHandleDrop = () => {
|
|
| 59 |
const addNode = useGraphStore((state) => state.addNode);
|
| 60 |
const [reactFlowInstance, setReactFlowInstance] =
|
| 61 |
useState<ReactFlowInstance<any, any>>();
|
|
|
|
| 62 |
|
| 63 |
const onDragOver = useCallback((event: React.DragEvent<HTMLDivElement>) => {
|
| 64 |
event.preventDefault();
|
|
@@ -93,6 +132,7 @@ export const useHandleDrop = () => {
|
|
| 93 |
data: {
|
| 94 |
label: `${type}`,
|
| 95 |
name: humanId(),
|
|
|
|
| 96 |
},
|
| 97 |
sourcePosition: Position.Right,
|
| 98 |
targetPosition: Position.Left,
|
|
@@ -100,7 +140,7 @@ export const useHandleDrop = () => {
|
|
| 100 |
|
| 101 |
addNode(newNode);
|
| 102 |
},
|
| 103 |
-
[reactFlowInstance, addNode],
|
| 104 |
);
|
| 105 |
|
| 106 |
return { onDrop, onDragOver, setReactFlowInstance };
|
|
@@ -244,7 +284,10 @@ export const useSetLlmSetting = (form?: FormInstance) => {
|
|
| 244 |
return pre;
|
| 245 |
}, {});
|
| 246 |
const otherValues = settledModelVariableMap[ModelVariableType.Precise];
|
| 247 |
-
form?.setFieldsValue({
|
|
|
|
|
|
|
|
|
|
| 248 |
}, [form, initialLlmSetting]);
|
| 249 |
};
|
| 250 |
|
|
|
|
| 17 |
ModelVariableType,
|
| 18 |
settledModelVariableMap,
|
| 19 |
} from '@/constants/knowledge';
|
| 20 |
+
import { useFetchModelId } from '@/hooks/logicHooks';
|
| 21 |
import { Variable } from '@/interfaces/database/chat';
|
| 22 |
import { useDebounceEffect } from 'ahooks';
|
| 23 |
import { FormInstance, message } from 'antd';
|
| 24 |
import { humanId } from 'human-id';
|
| 25 |
import trim from 'lodash/trim';
|
| 26 |
import { useParams } from 'umi';
|
| 27 |
+
import {
|
| 28 |
+
NodeMap,
|
| 29 |
+
Operator,
|
| 30 |
+
RestrictedUpstreamMap,
|
| 31 |
+
initialBeginValues,
|
| 32 |
+
initialCategorizeValues,
|
| 33 |
+
initialGenerateValues,
|
| 34 |
+
initialMessageValues,
|
| 35 |
+
initialRelevantValues,
|
| 36 |
+
initialRetrievalValues,
|
| 37 |
+
initialRewriteQuestionValues,
|
| 38 |
+
} from './constant';
|
| 39 |
import useGraphStore, { RFState } from './store';
|
| 40 |
import { buildDslComponentsByGraph } from './utils';
|
| 41 |
|
|
|
|
| 55 |
return useGraphStore(selector);
|
| 56 |
};
|
| 57 |
|
| 58 |
+
export const useInitializeOperatorParams = () => {
|
| 59 |
+
const llmId = useFetchModelId(true);
|
| 60 |
+
|
| 61 |
+
const initializeOperatorParams = useCallback(
|
| 62 |
+
(operatorName: Operator) => {
|
| 63 |
+
const initialFormValuesMap = {
|
| 64 |
+
[Operator.Begin]: initialBeginValues,
|
| 65 |
+
[Operator.Retrieval]: initialRetrievalValues,
|
| 66 |
+
[Operator.Generate]: { ...initialGenerateValues, llm_id: llmId },
|
| 67 |
+
[Operator.Answer]: {},
|
| 68 |
+
[Operator.Categorize]: { ...initialCategorizeValues, llm_id: llmId },
|
| 69 |
+
[Operator.Relevant]: { ...initialRelevantValues, llm_id: llmId },
|
| 70 |
+
[Operator.RewriteQuestion]: {
|
| 71 |
+
...initialRewriteQuestionValues,
|
| 72 |
+
llm_id: llmId,
|
| 73 |
+
},
|
| 74 |
+
[Operator.Message]: initialMessageValues,
|
| 75 |
+
};
|
| 76 |
+
return initialFormValuesMap[operatorName];
|
| 77 |
+
},
|
| 78 |
+
[llmId],
|
| 79 |
+
);
|
| 80 |
+
|
| 81 |
+
return initializeOperatorParams;
|
| 82 |
+
};
|
| 83 |
+
|
| 84 |
export const useHandleDrag = () => {
|
| 85 |
const handleDragStart = useCallback(
|
| 86 |
(operatorId: string) => (ev: React.DragEvent<HTMLDivElement>) => {
|
|
|
|
| 97 |
const addNode = useGraphStore((state) => state.addNode);
|
| 98 |
const [reactFlowInstance, setReactFlowInstance] =
|
| 99 |
useState<ReactFlowInstance<any, any>>();
|
| 100 |
+
const initializeOperatorParams = useInitializeOperatorParams();
|
| 101 |
|
| 102 |
const onDragOver = useCallback((event: React.DragEvent<HTMLDivElement>) => {
|
| 103 |
event.preventDefault();
|
|
|
|
| 132 |
data: {
|
| 133 |
label: `${type}`,
|
| 134 |
name: humanId(),
|
| 135 |
+
form: initializeOperatorParams(type as Operator),
|
| 136 |
},
|
| 137 |
sourcePosition: Position.Right,
|
| 138 |
targetPosition: Position.Left,
|
|
|
|
| 140 |
|
| 141 |
addNode(newNode);
|
| 142 |
},
|
| 143 |
+
[reactFlowInstance, addNode, initializeOperatorParams],
|
| 144 |
);
|
| 145 |
|
| 146 |
return { onDrop, onDragOver, setReactFlowInstance };
|
|
|
|
| 284 |
return pre;
|
| 285 |
}, {});
|
| 286 |
const otherValues = settledModelVariableMap[ModelVariableType.Precise];
|
| 287 |
+
form?.setFieldsValue({
|
| 288 |
+
...switchBoxValues,
|
| 289 |
+
...otherValues,
|
| 290 |
+
});
|
| 291 |
}, [form, initialLlmSetting]);
|
| 292 |
};
|
| 293 |
|
web/src/pages/flow/list/index.less
CHANGED
|
@@ -56,6 +56,6 @@
|
|
| 56 |
}
|
| 57 |
|
| 58 |
.templatesBox {
|
| 59 |
-
max-height: 500px;
|
| 60 |
overflow: auto;
|
| 61 |
}
|
|
|
|
| 56 |
}
|
| 57 |
|
| 58 |
.templatesBox {
|
| 59 |
+
// max-height: 500px;
|
| 60 |
overflow: auto;
|
| 61 |
}
|
web/src/pages/flow/utils.ts
CHANGED
|
@@ -2,11 +2,11 @@ import { DSLComponents } from '@/interfaces/database/flow';
|
|
| 2 |
import { removeUselessFieldsFromValues } from '@/utils/form';
|
| 3 |
import dagre from 'dagre';
|
| 4 |
import { humanId } from 'human-id';
|
| 5 |
-
import { curry
|
| 6 |
import pipe from 'lodash/fp/pipe';
|
| 7 |
import { Edge, Node, Position } from 'reactflow';
|
| 8 |
import { v4 as uuidv4 } from 'uuid';
|
| 9 |
-
import { NodeMap, Operator
|
| 10 |
import { ICategorizeItemResult, NodeData } from './interface';
|
| 11 |
|
| 12 |
const buildEdges = (
|
|
@@ -143,17 +143,17 @@ const removeUselessDataInTheOperator = curry(
|
|
| 143 |
},
|
| 144 |
);
|
| 145 |
// initialize data for operators without parameters
|
| 146 |
-
const initializeOperatorParams = curry((operatorName: string, values: any) => {
|
| 147 |
-
|
| 148 |
-
|
| 149 |
-
|
| 150 |
-
|
| 151 |
-
});
|
| 152 |
|
| 153 |
const buildOperatorParams = (operatorName: string) =>
|
| 154 |
pipe(
|
| 155 |
removeUselessDataInTheOperator(operatorName),
|
| 156 |
-
initializeOperatorParams(operatorName), // Final processing, for guarantee
|
| 157 |
);
|
| 158 |
|
| 159 |
// construct a dsl based on the node information of the graph
|
|
|
|
| 2 |
import { removeUselessFieldsFromValues } from '@/utils/form';
|
| 3 |
import dagre from 'dagre';
|
| 4 |
import { humanId } from 'human-id';
|
| 5 |
+
import { curry } from 'lodash';
|
| 6 |
import pipe from 'lodash/fp/pipe';
|
| 7 |
import { Edge, Node, Position } from 'reactflow';
|
| 8 |
import { v4 as uuidv4 } from 'uuid';
|
| 9 |
+
import { NodeMap, Operator } from './constant';
|
| 10 |
import { ICategorizeItemResult, NodeData } from './interface';
|
| 11 |
|
| 12 |
const buildEdges = (
|
|
|
|
| 143 |
},
|
| 144 |
);
|
| 145 |
// initialize data for operators without parameters
|
| 146 |
+
// const initializeOperatorParams = curry((operatorName: string, values: any) => {
|
| 147 |
+
// if (isEmpty(values)) {
|
| 148 |
+
// return initialFormValuesMap[operatorName as Operator];
|
| 149 |
+
// }
|
| 150 |
+
// return values;
|
| 151 |
+
// });
|
| 152 |
|
| 153 |
const buildOperatorParams = (operatorName: string) =>
|
| 154 |
pipe(
|
| 155 |
removeUselessDataInTheOperator(operatorName),
|
| 156 |
+
// initializeOperatorParams(operatorName), // Final processing, for guarantee
|
| 157 |
);
|
| 158 |
|
| 159 |
// construct a dsl based on the node information of the graph
|