balibabu
commited on
Commit
·
13080d4
1
Parent(s):
2c22625
feat: fetch flow (#1068)
Browse files### What problem does this PR solve?
feat: fetch flow #918
feat: save graph
### Type of change
- [x] New Feature (non-breaking change which adds functionality)
- web/package.json +1 -1
- web/src/components/similarity-slider/index.tsx +8 -4
- web/src/constants/chat.ts +8 -0
- web/src/hooks/flow-hooks.ts +24 -2
- web/src/interfaces/database/flow.ts +31 -3
- web/src/pages/chat/chat-configuration-modal/index.tsx +5 -8
- web/src/pages/chat/chat-configuration-modal/model-setting.tsx +1 -1
- web/src/pages/chat/constants.ts +0 -8
- web/src/pages/chat/utils.ts +1 -12
- web/src/pages/flow/begin-form/index.tsx +1 -2
- web/src/pages/flow/constant.ts +26 -0
- web/src/pages/flow/flow-drawer/index.tsx +14 -2
- web/src/pages/flow/generate-form/index.tsx +4 -5
- web/src/pages/flow/hooks.ts +55 -6
- web/src/pages/flow/interface.ts +2 -21
- web/src/pages/flow/list/flow-card/index.tsx +1 -1
- web/src/pages/flow/list/index.tsx +2 -2
- web/src/pages/flow/retrieval-form/index.tsx +5 -4
- web/src/pages/flow/store.ts +2 -5
- web/src/pages/flow/utils.ts +18 -2
- web/src/utils/form.ts +28 -0
- web/src/utils/registerServer.ts +4 -1
web/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1 |
{
|
2 |
"private": true,
|
3 |
-
"author": "
|
4 |
"scripts": {
|
5 |
"build": "umi build",
|
6 |
"dev": "cross-env UMI_DEV_SERVER_COMPRESS=none umi dev",
|
|
|
1 |
{
|
2 |
"private": true,
|
3 |
+
"author": "bill",
|
4 |
"scripts": {
|
5 |
"build": "umi build",
|
6 |
"dev": "cross-env UMI_DEV_SERVER_COMPRESS=none umi dev",
|
web/src/components/similarity-slider/index.tsx
CHANGED
@@ -3,14 +3,18 @@ import { Form, Slider } from 'antd';
|
|
3 |
|
4 |
type FieldType = {
|
5 |
similarity_threshold?: number;
|
6 |
-
vector_similarity_weight?: number;
|
7 |
};
|
8 |
|
9 |
interface IProps {
|
10 |
isTooltipShown?: boolean;
|
|
|
11 |
}
|
12 |
|
13 |
-
const SimilaritySlider = ({
|
|
|
|
|
|
|
14 |
const { t } = useTranslate('knowledgeDetails');
|
15 |
|
16 |
return (
|
@@ -23,9 +27,9 @@ const SimilaritySlider = ({ isTooltipShown = false }: IProps) => {
|
|
23 |
>
|
24 |
<Slider max={1} step={0.01} />
|
25 |
</Form.Item>
|
26 |
-
<Form.Item
|
27 |
label={t('vectorSimilarityWeight')}
|
28 |
-
name={
|
29 |
initialValue={1 - 0.3}
|
30 |
tooltip={isTooltipShown && t('vectorSimilarityWeightTip')}
|
31 |
>
|
|
|
3 |
|
4 |
type FieldType = {
|
5 |
similarity_threshold?: number;
|
6 |
+
// vector_similarity_weight?: number;
|
7 |
};
|
8 |
|
9 |
interface IProps {
|
10 |
isTooltipShown?: boolean;
|
11 |
+
vectorSimilarityWeightName?: string;
|
12 |
}
|
13 |
|
14 |
+
const SimilaritySlider = ({
|
15 |
+
isTooltipShown = false,
|
16 |
+
vectorSimilarityWeightName = 'vector_similarity_weight',
|
17 |
+
}: IProps) => {
|
18 |
const { t } = useTranslate('knowledgeDetails');
|
19 |
|
20 |
return (
|
|
|
27 |
>
|
28 |
<Slider max={1} step={0.01} />
|
29 |
</Form.Item>
|
30 |
+
<Form.Item
|
31 |
label={t('vectorSimilarityWeight')}
|
32 |
+
name={vectorSimilarityWeightName}
|
33 |
initialValue={1 - 0.3}
|
34 |
tooltip={isTooltipShown && t('vectorSimilarityWeightTip')}
|
35 |
>
|
web/src/constants/chat.ts
CHANGED
@@ -2,3 +2,11 @@ export enum MessageType {
|
|
2 |
Assistant = 'assistant',
|
3 |
User = 'user',
|
4 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2 |
Assistant = 'assistant',
|
3 |
User = 'user',
|
4 |
}
|
5 |
+
|
6 |
+
export const variableEnabledFieldMap = {
|
7 |
+
temperatureEnabled: 'temperature',
|
8 |
+
topPEnabled: 'top_p',
|
9 |
+
presencePenaltyEnabled: 'presence_penalty',
|
10 |
+
frequencyPenaltyEnabled: 'frequency_penalty',
|
11 |
+
maxTokensEnabled: 'max_tokens',
|
12 |
+
};
|
web/src/hooks/flow-hooks.ts
CHANGED
@@ -1,5 +1,9 @@
|
|
|
|
|
|
1 |
import flowService from '@/services/flow-service';
|
2 |
import { useMutation, useQuery, useQueryClient } from '@tanstack/react-query';
|
|
|
|
|
3 |
|
4 |
export const useFetchFlowTemplates = () => {
|
5 |
const { data } = useQuery({
|
@@ -15,7 +19,7 @@ export const useFetchFlowTemplates = () => {
|
|
15 |
return data;
|
16 |
};
|
17 |
|
18 |
-
export const useFetchFlowList = () => {
|
19 |
const { data, isFetching: loading } = useQuery({
|
20 |
queryKey: ['fetchFlowList'],
|
21 |
initialData: [],
|
@@ -29,6 +33,21 @@ export const useFetchFlowList = () => {
|
|
29 |
return { data, loading };
|
30 |
};
|
31 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
32 |
export const useSetFlow = () => {
|
33 |
const queryClient = useQueryClient();
|
34 |
const {
|
@@ -37,9 +56,12 @@ export const useSetFlow = () => {
|
|
37 |
mutateAsync,
|
38 |
} = useMutation({
|
39 |
mutationKey: ['setFlow'],
|
40 |
-
mutationFn: async (params:
|
41 |
const { data } = await flowService.setCanvas(params);
|
42 |
if (data.retcode === 0) {
|
|
|
|
|
|
|
43 |
queryClient.invalidateQueries({ queryKey: ['fetchFlowList'] });
|
44 |
}
|
45 |
return data?.retcode;
|
|
|
1 |
+
import { DSL, IFlow } from '@/interfaces/database/flow';
|
2 |
+
import i18n from '@/locales/config';
|
3 |
import flowService from '@/services/flow-service';
|
4 |
import { useMutation, useQuery, useQueryClient } from '@tanstack/react-query';
|
5 |
+
import { message } from 'antd';
|
6 |
+
import { useParams } from 'umi';
|
7 |
|
8 |
export const useFetchFlowTemplates = () => {
|
9 |
const { data } = useQuery({
|
|
|
19 |
return data;
|
20 |
};
|
21 |
|
22 |
+
export const useFetchFlowList = (): { data: IFlow[]; loading: boolean } => {
|
23 |
const { data, isFetching: loading } = useQuery({
|
24 |
queryKey: ['fetchFlowList'],
|
25 |
initialData: [],
|
|
|
33 |
return { data, loading };
|
34 |
};
|
35 |
|
36 |
+
export const useFetchFlow = (): { data: IFlow; loading: boolean } => {
|
37 |
+
const { id } = useParams();
|
38 |
+
const { data, isFetching: loading } = useQuery({
|
39 |
+
queryKey: ['flowDetail'],
|
40 |
+
initialData: {} as IFlow,
|
41 |
+
queryFn: async () => {
|
42 |
+
const { data } = await flowService.getCanvas({}, id);
|
43 |
+
|
44 |
+
return data?.data ?? {};
|
45 |
+
},
|
46 |
+
});
|
47 |
+
|
48 |
+
return { data, loading };
|
49 |
+
};
|
50 |
+
|
51 |
export const useSetFlow = () => {
|
52 |
const queryClient = useQueryClient();
|
53 |
const {
|
|
|
56 |
mutateAsync,
|
57 |
} = useMutation({
|
58 |
mutationKey: ['setFlow'],
|
59 |
+
mutationFn: async (params: { id?: string; title?: string; dsl?: DSL }) => {
|
60 |
const { data } = await flowService.setCanvas(params);
|
61 |
if (data.retcode === 0) {
|
62 |
+
message.success(
|
63 |
+
i18n.t(`message.${params?.id ? 'modified' : 'created'}`),
|
64 |
+
);
|
65 |
queryClient.invalidateQueries({ queryKey: ['fetchFlowList'] });
|
66 |
}
|
67 |
return data?.retcode;
|
web/src/interfaces/database/flow.ts
CHANGED
@@ -1,10 +1,13 @@
|
|
|
|
|
|
1 |
export type DSLComponents = Record<string, IOperator>;
|
2 |
|
3 |
export interface DSL {
|
4 |
components: DSLComponents;
|
5 |
-
history
|
6 |
-
path
|
7 |
-
answer
|
|
|
8 |
}
|
9 |
|
10 |
export interface IOperator {
|
@@ -17,3 +20,28 @@ export interface IOperatorNode {
|
|
17 |
component_name: string;
|
18 |
params: Record<string, unknown>;
|
19 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import { Edge, Node } from 'reactflow';
|
2 |
+
|
3 |
export type DSLComponents = Record<string, IOperator>;
|
4 |
|
5 |
export interface DSL {
|
6 |
components: DSLComponents;
|
7 |
+
history?: any[];
|
8 |
+
path?: string[];
|
9 |
+
answer?: any[];
|
10 |
+
graph?: IGraph;
|
11 |
}
|
12 |
|
13 |
export interface IOperator {
|
|
|
20 |
component_name: string;
|
21 |
params: Record<string, unknown>;
|
22 |
}
|
23 |
+
|
24 |
+
export interface IGraph {
|
25 |
+
nodes: Node[];
|
26 |
+
edges: Edge[];
|
27 |
+
}
|
28 |
+
|
29 |
+
export interface IFlow {
|
30 |
+
avatar: null;
|
31 |
+
canvas_type: null;
|
32 |
+
create_date: string;
|
33 |
+
create_time: number;
|
34 |
+
description: null;
|
35 |
+
dsl: {
|
36 |
+
answer: any[];
|
37 |
+
components: DSLComponents;
|
38 |
+
graph: IGraph;
|
39 |
+
history: any[];
|
40 |
+
path: string[];
|
41 |
+
};
|
42 |
+
id: string;
|
43 |
+
title: string;
|
44 |
+
update_date: string;
|
45 |
+
update_time: number;
|
46 |
+
user_id: string;
|
47 |
+
}
|
web/src/pages/chat/chat-configuration-modal/index.tsx
CHANGED
@@ -8,11 +8,8 @@ import { IDialog } from '@/interfaces/database/chat';
|
|
8 |
import { Divider, Flex, Form, Modal, Segmented, UploadFile } from 'antd';
|
9 |
import { SegmentedValue } from 'antd/es/segmented';
|
10 |
import camelCase from 'lodash/camelCase';
|
11 |
-
import omit from 'lodash/omit';
|
12 |
import { useEffect, useRef, useState } from 'react';
|
13 |
-
import { variableEnabledFieldMap } from '../constants';
|
14 |
import { IPromptConfigParameters } from '../interface';
|
15 |
-
import { excludeUnEnabledVariables } from '../utils';
|
16 |
import AssistantSetting from './assistant-setting';
|
17 |
import { useFetchLlmModelOnVisible, useFetchModelId } from './hooks';
|
18 |
import ModelSetting from './model-setting';
|
@@ -20,6 +17,7 @@ import PromptEngine from './prompt-engine';
|
|
20 |
|
21 |
import { useTranslate } from '@/hooks/commonHooks';
|
22 |
import { getBase64FromUploadFileList } from '@/utils/fileUtil';
|
|
|
23 |
import styles from './index.less';
|
24 |
|
25 |
const layout = {
|
@@ -76,11 +74,10 @@ const ChatConfigurationModal = ({
|
|
76 |
|
77 |
const handleOk = async () => {
|
78 |
const values = await form.validateFields();
|
79 |
-
const nextValues: any =
|
80 |
-
|
81 |
-
'
|
82 |
-
|
83 |
-
]);
|
84 |
const emptyResponse = nextValues.prompt_config?.empty_response ?? '';
|
85 |
|
86 |
const icon = await getBase64FromUploadFileList(values.icon);
|
|
|
8 |
import { Divider, Flex, Form, Modal, Segmented, UploadFile } from 'antd';
|
9 |
import { SegmentedValue } from 'antd/es/segmented';
|
10 |
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';
|
|
|
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';
|
22 |
|
23 |
const layout = {
|
|
|
74 |
|
75 |
const handleOk = async () => {
|
76 |
const values = await form.validateFields();
|
77 |
+
const nextValues: any = removeUselessFieldsFromValues(
|
78 |
+
values,
|
79 |
+
'llm_setting.',
|
80 |
+
);
|
|
|
81 |
const emptyResponse = nextValues.prompt_config?.empty_response ?? '';
|
82 |
|
83 |
const icon = await getBase64FromUploadFileList(values.icon);
|
web/src/pages/chat/chat-configuration-modal/model-setting.tsx
CHANGED
@@ -7,8 +7,8 @@ import { useEffect } from 'react';
|
|
7 |
import { ISegmentedContentProps } from '../interface';
|
8 |
|
9 |
import LlmSettingItems from '@/components/llm-setting-items';
|
|
|
10 |
import { Variable } from '@/interfaces/database/chat';
|
11 |
-
import { variableEnabledFieldMap } from '../constants';
|
12 |
import styles from './index.less';
|
13 |
|
14 |
const ModelSetting = ({
|
|
|
7 |
import { ISegmentedContentProps } from '../interface';
|
8 |
|
9 |
import LlmSettingItems from '@/components/llm-setting-items';
|
10 |
+
import { variableEnabledFieldMap } from '@/constants/chat';
|
11 |
import { Variable } from '@/interfaces/database/chat';
|
|
|
12 |
import styles from './index.less';
|
13 |
|
14 |
const ModelSetting = ({
|
web/src/pages/chat/constants.ts
CHANGED
@@ -1,11 +1,3 @@
|
|
1 |
-
export const variableEnabledFieldMap = {
|
2 |
-
temperatureEnabled: 'temperature',
|
3 |
-
topPEnabled: 'top_p',
|
4 |
-
presencePenaltyEnabled: 'presence_penalty',
|
5 |
-
frequencyPenaltyEnabled: 'frequency_penalty',
|
6 |
-
maxTokensEnabled: 'max_tokens',
|
7 |
-
};
|
8 |
-
|
9 |
export enum ChatSearchParams {
|
10 |
DialogId = 'dialogId',
|
11 |
ConversationId = 'conversationId',
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
export enum ChatSearchParams {
|
2 |
DialogId = 'dialogId',
|
3 |
ConversationId = 'conversationId',
|
web/src/pages/chat/utils.ts
CHANGED
@@ -1,19 +1,8 @@
|
|
1 |
import { MessageType } from '@/constants/chat';
|
2 |
import { IConversation, IReference } from '@/interfaces/database/chat';
|
3 |
-
import { EmptyConversationId
|
4 |
import { IClientConversation, IMessage } from './interface';
|
5 |
|
6 |
-
export const excludeUnEnabledVariables = (values: any) => {
|
7 |
-
const unEnabledFields: Array<keyof typeof variableEnabledFieldMap> =
|
8 |
-
Object.keys(variableEnabledFieldMap).filter((key) => !values[key]) as Array<
|
9 |
-
keyof typeof variableEnabledFieldMap
|
10 |
-
>;
|
11 |
-
|
12 |
-
return unEnabledFields.map(
|
13 |
-
(key) => `llm_setting.${variableEnabledFieldMap[key]}`,
|
14 |
-
);
|
15 |
-
};
|
16 |
-
|
17 |
export const isConversationIdExist = (conversationId: string) => {
|
18 |
return conversationId !== EmptyConversationId && conversationId !== '';
|
19 |
};
|
|
|
1 |
import { MessageType } from '@/constants/chat';
|
2 |
import { IConversation, IReference } from '@/interfaces/database/chat';
|
3 |
+
import { EmptyConversationId } from './constants';
|
4 |
import { IClientConversation, IMessage } from './interface';
|
5 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
6 |
export const isConversationIdExist = (conversationId: string) => {
|
7 |
return conversationId !== EmptyConversationId && conversationId !== '';
|
8 |
};
|
web/src/pages/flow/begin-form/index.tsx
CHANGED
@@ -15,9 +15,8 @@ const onFinishFailed: FormProps<FieldType>['onFinishFailed'] = (errorInfo) => {
|
|
15 |
console.log('Failed:', errorInfo);
|
16 |
};
|
17 |
|
18 |
-
const BeginForm = ({ onValuesChange }: IOperatorForm) => {
|
19 |
const { t } = useTranslate('chat');
|
20 |
-
const [form] = Form.useForm();
|
21 |
|
22 |
return (
|
23 |
<Form
|
|
|
15 |
console.log('Failed:', errorInfo);
|
16 |
};
|
17 |
|
18 |
+
const BeginForm = ({ onValuesChange, form }: IOperatorForm) => {
|
19 |
const { t } = useTranslate('chat');
|
|
|
20 |
|
21 |
return (
|
22 |
<Form
|
web/src/pages/flow/constant.ts
CHANGED
@@ -1,6 +1,32 @@
|
|
|
|
|
|
1 |
export enum Operator {
|
2 |
Begin = 'Begin',
|
3 |
Retrieval = 'Retrieval',
|
4 |
Generate = 'Generate',
|
5 |
Answer = 'Answer',
|
6 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import { ModelVariableType } from '@/constants/knowledge';
|
2 |
+
|
3 |
export enum Operator {
|
4 |
Begin = 'Begin',
|
5 |
Retrieval = 'Retrieval',
|
6 |
Generate = 'Generate',
|
7 |
Answer = 'Answer',
|
8 |
}
|
9 |
+
|
10 |
+
export const initialRetrievalValues = {
|
11 |
+
similarity_threshold: 0.2,
|
12 |
+
keywords_similarity_weight: 0.3,
|
13 |
+
top_n: 8,
|
14 |
+
};
|
15 |
+
|
16 |
+
export const initialBeginValues = {
|
17 |
+
prologue: `Hi! I'm your assistant, what can I do for you?`,
|
18 |
+
};
|
19 |
+
|
20 |
+
export const initialGenerateValues = {
|
21 |
+
parameters: ModelVariableType.Precise,
|
22 |
+
temperatureEnabled: false,
|
23 |
+
temperature: 0.1,
|
24 |
+
top_p: 0.3,
|
25 |
+
frequency_penalty: 0.7,
|
26 |
+
presence_penalty: 0.4,
|
27 |
+
max_tokens: 512,
|
28 |
+
prompt: `Please summarize the following paragraphs. Be careful with the numbers, do not make things up. Paragraphs as following:
|
29 |
+
{cluster_content}
|
30 |
+
The above is the content you need to summarize.`,
|
31 |
+
cite: true,
|
32 |
+
};
|
web/src/pages/flow/flow-drawer/index.tsx
CHANGED
@@ -1,5 +1,6 @@
|
|
1 |
import { IModalProps } from '@/interfaces/common';
|
2 |
-
import { Drawer } from 'antd';
|
|
|
3 |
import { Node } from 'reactflow';
|
4 |
import AnswerForm from '../answer-form';
|
5 |
import BeginForm from '../begin-form';
|
@@ -26,8 +27,16 @@ const FlowDrawer = ({
|
|
26 |
}: IModalProps<any> & IProps) => {
|
27 |
const operatorName: Operator = node?.data.label;
|
28 |
const OperatorForm = FormMap[operatorName];
|
|
|
|
|
29 |
const { handleValuesChange } = useHandleFormValuesChange(node?.id);
|
30 |
|
|
|
|
|
|
|
|
|
|
|
|
|
31 |
return (
|
32 |
<Drawer
|
33 |
title={node?.data.label}
|
@@ -39,7 +48,10 @@ const FlowDrawer = ({
|
|
39 |
width={470}
|
40 |
>
|
41 |
{visible && (
|
42 |
-
<OperatorForm
|
|
|
|
|
|
|
43 |
)}
|
44 |
</Drawer>
|
45 |
);
|
|
|
1 |
import { IModalProps } from '@/interfaces/common';
|
2 |
+
import { Drawer, Form } from 'antd';
|
3 |
+
import { useEffect } from 'react';
|
4 |
import { Node } from 'reactflow';
|
5 |
import AnswerForm from '../answer-form';
|
6 |
import BeginForm from '../begin-form';
|
|
|
27 |
}: IModalProps<any> & IProps) => {
|
28 |
const operatorName: Operator = node?.data.label;
|
29 |
const OperatorForm = FormMap[operatorName];
|
30 |
+
const [form] = Form.useForm();
|
31 |
+
|
32 |
const { handleValuesChange } = useHandleFormValuesChange(node?.id);
|
33 |
|
34 |
+
useEffect(() => {
|
35 |
+
if (visible) {
|
36 |
+
form.setFieldsValue(node?.data?.form);
|
37 |
+
}
|
38 |
+
}, [visible, form, node?.data?.form]);
|
39 |
+
|
40 |
return (
|
41 |
<Drawer
|
42 |
title={node?.data.label}
|
|
|
48 |
width={470}
|
49 |
>
|
50 |
{visible && (
|
51 |
+
<OperatorForm
|
52 |
+
onValuesChange={handleValuesChange}
|
53 |
+
form={form}
|
54 |
+
></OperatorForm>
|
55 |
)}
|
56 |
</Drawer>
|
57 |
);
|
web/src/pages/flow/generate-form/index.tsx
CHANGED
@@ -1,24 +1,23 @@
|
|
1 |
import LlmSettingItems from '@/components/llm-setting-items';
|
|
|
2 |
import {
|
3 |
ModelVariableType,
|
4 |
settledModelVariableMap,
|
5 |
} from '@/constants/knowledge';
|
6 |
import { useTranslate } from '@/hooks/commonHooks';
|
7 |
import { Variable } from '@/interfaces/database/chat';
|
8 |
-
import { variableEnabledFieldMap } from '@/pages/chat/constants';
|
9 |
import { Form, Input, Switch } from 'antd';
|
10 |
import { useCallback, useEffect } from 'react';
|
11 |
import { IOperatorForm } from '../interface';
|
12 |
|
13 |
-
const GenerateForm = ({ onValuesChange }: IOperatorForm) => {
|
14 |
const { t } = useTranslate('flow');
|
15 |
-
const [form] = Form.useForm();
|
16 |
const initialLlmSetting = undefined;
|
17 |
|
18 |
const handleParametersChange = useCallback(
|
19 |
(value: ModelVariableType) => {
|
20 |
const variable = settledModelVariableMap[value];
|
21 |
-
form
|
22 |
},
|
23 |
[form],
|
24 |
);
|
@@ -38,7 +37,7 @@ const GenerateForm = ({ onValuesChange }: IOperatorForm) => {
|
|
38 |
return pre;
|
39 |
}, {});
|
40 |
const otherValues = settledModelVariableMap[ModelVariableType.Precise];
|
41 |
-
form
|
42 |
}, [form, initialLlmSetting]);
|
43 |
|
44 |
return (
|
|
|
1 |
import LlmSettingItems from '@/components/llm-setting-items';
|
2 |
+
import { variableEnabledFieldMap } from '@/constants/chat';
|
3 |
import {
|
4 |
ModelVariableType,
|
5 |
settledModelVariableMap,
|
6 |
} from '@/constants/knowledge';
|
7 |
import { useTranslate } from '@/hooks/commonHooks';
|
8 |
import { Variable } from '@/interfaces/database/chat';
|
|
|
9 |
import { Form, Input, Switch } from 'antd';
|
10 |
import { useCallback, useEffect } from 'react';
|
11 |
import { IOperatorForm } from '../interface';
|
12 |
|
13 |
+
const GenerateForm = ({ onValuesChange, form }: IOperatorForm) => {
|
14 |
const { t } = useTranslate('flow');
|
|
|
15 |
const initialLlmSetting = undefined;
|
16 |
|
17 |
const handleParametersChange = useCallback(
|
18 |
(value: ModelVariableType) => {
|
19 |
const variable = settledModelVariableMap[value];
|
20 |
+
form?.setFieldsValue(variable);
|
21 |
},
|
22 |
[form],
|
23 |
);
|
|
|
37 |
return pre;
|
38 |
}, {});
|
39 |
const otherValues = settledModelVariableMap[ModelVariableType.Precise];
|
40 |
+
form?.setFieldsValue({ ...switchBoxValues, ...otherValues });
|
41 |
}, [form, initialLlmSetting]);
|
42 |
|
43 |
return (
|
web/src/pages/flow/hooks.ts
CHANGED
@@ -1,9 +1,22 @@
|
|
1 |
import { useSetModalState } from '@/hooks/commonHooks';
|
2 |
-
import {
|
|
|
|
|
|
|
|
|
3 |
import { useFetchLlmList } from '@/hooks/llmHooks';
|
4 |
-
import
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
5 |
import { Node, Position, ReactFlowInstance } from 'reactflow';
|
6 |
import { v4 as uuidv4 } from 'uuid';
|
|
|
|
|
7 |
import useStore, { RFState } from './store';
|
8 |
import { buildDslComponentsByGraph } from './utils';
|
9 |
|
@@ -18,7 +31,8 @@ const selector = (state: RFState) => ({
|
|
18 |
});
|
19 |
|
20 |
export const useSelectCanvasData = () => {
|
21 |
-
// return useStore(useShallow(selector)); throw error
|
|
|
22 |
return useStore(selector);
|
23 |
};
|
24 |
|
@@ -121,11 +135,19 @@ export const useHandleKeyUp = () => {
|
|
121 |
};
|
122 |
|
123 |
export const useSaveGraph = () => {
|
|
|
|
|
|
|
124 |
const { nodes, edges } = useStore((state) => state);
|
125 |
const saveGraph = useCallback(() => {
|
126 |
-
const
|
127 |
-
console.info('components:',
|
128 |
-
|
|
|
|
|
|
|
|
|
|
|
129 |
|
130 |
return { saveGraph };
|
131 |
};
|
@@ -145,7 +167,34 @@ export const useHandleFormValuesChange = (id?: string) => {
|
|
145 |
return { handleValuesChange };
|
146 |
};
|
147 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
148 |
export const useFetchDataOnMount = () => {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
149 |
useFetchFlowTemplates();
|
150 |
useFetchLlmList();
|
|
|
|
|
|
|
|
|
|
|
|
|
151 |
};
|
|
|
1 |
import { useSetModalState } from '@/hooks/commonHooks';
|
2 |
+
import {
|
3 |
+
useFetchFlow,
|
4 |
+
useFetchFlowTemplates,
|
5 |
+
useSetFlow,
|
6 |
+
} from '@/hooks/flow-hooks';
|
7 |
import { useFetchLlmList } from '@/hooks/llmHooks';
|
8 |
+
import { IGraph } from '@/interfaces/database/flow';
|
9 |
+
import { useIsFetching } from '@tanstack/react-query';
|
10 |
+
import React, {
|
11 |
+
KeyboardEventHandler,
|
12 |
+
useCallback,
|
13 |
+
useEffect,
|
14 |
+
useState,
|
15 |
+
} from 'react';
|
16 |
import { Node, Position, ReactFlowInstance } from 'reactflow';
|
17 |
import { v4 as uuidv4 } from 'uuid';
|
18 |
+
// import { shallow } from 'zustand/shallow';
|
19 |
+
import { useParams } from 'umi';
|
20 |
import useStore, { RFState } from './store';
|
21 |
import { buildDslComponentsByGraph } from './utils';
|
22 |
|
|
|
31 |
});
|
32 |
|
33 |
export const useSelectCanvasData = () => {
|
34 |
+
// return useStore(useShallow(selector)); // throw error
|
35 |
+
// return useStore(selector, shallow);
|
36 |
return useStore(selector);
|
37 |
};
|
38 |
|
|
|
135 |
};
|
136 |
|
137 |
export const useSaveGraph = () => {
|
138 |
+
const { data } = useFetchFlow();
|
139 |
+
const { setFlow } = useSetFlow();
|
140 |
+
const { id } = useParams();
|
141 |
const { nodes, edges } = useStore((state) => state);
|
142 |
const saveGraph = useCallback(() => {
|
143 |
+
const dslComponents = buildDslComponentsByGraph(nodes, edges);
|
144 |
+
console.info('components:', dslComponents);
|
145 |
+
setFlow({
|
146 |
+
id,
|
147 |
+
title: data.title,
|
148 |
+
dsl: { ...data.dsl, graph: { nodes, edges }, components: dslComponents },
|
149 |
+
});
|
150 |
+
}, [nodes, edges, setFlow, id, data]);
|
151 |
|
152 |
return { saveGraph };
|
153 |
};
|
|
|
167 |
return { handleValuesChange };
|
168 |
};
|
169 |
|
170 |
+
const useSetGraphInfo = () => {
|
171 |
+
const { setEdges, setNodes } = useStore((state) => state);
|
172 |
+
const setGraphInfo = useCallback(
|
173 |
+
({ nodes = [], edges = [] }: IGraph) => {
|
174 |
+
if (nodes.length && edges.length) {
|
175 |
+
setNodes(nodes);
|
176 |
+
setEdges(edges);
|
177 |
+
}
|
178 |
+
},
|
179 |
+
[setEdges, setNodes],
|
180 |
+
);
|
181 |
+
return setGraphInfo;
|
182 |
+
};
|
183 |
+
|
184 |
export const useFetchDataOnMount = () => {
|
185 |
+
const { loading, data } = useFetchFlow();
|
186 |
+
const setGraphInfo = useSetGraphInfo();
|
187 |
+
|
188 |
+
useEffect(() => {
|
189 |
+
setGraphInfo(data?.dsl?.graph ?? {});
|
190 |
+
}, [setGraphInfo, data?.dsl?.graph]);
|
191 |
+
|
192 |
useFetchFlowTemplates();
|
193 |
useFetchLlmList();
|
194 |
+
|
195 |
+
return { loading, flowDetail: data };
|
196 |
+
};
|
197 |
+
|
198 |
+
export const useFlowIsFetching = () => {
|
199 |
+
return useIsFetching({ queryKey: ['flowDetail'] }) > 0;
|
200 |
};
|
web/src/pages/flow/interface.ts
CHANGED
@@ -1,4 +1,4 @@
|
|
1 |
-
import {
|
2 |
|
3 |
export interface DSLComponentList {
|
4 |
id: string;
|
@@ -7,6 +7,7 @@ export interface DSLComponentList {
|
|
7 |
|
8 |
export interface IOperatorForm {
|
9 |
onValuesChange?(changedValues: any, values: any): void;
|
|
|
10 |
}
|
11 |
|
12 |
export interface IBeginForm {
|
@@ -40,23 +41,3 @@ export type NodeData = {
|
|
40 |
color: string;
|
41 |
form: IBeginForm | IRetrievalForm | IGenerateForm;
|
42 |
};
|
43 |
-
|
44 |
-
export interface IFlow {
|
45 |
-
avatar: null;
|
46 |
-
canvas_type: null;
|
47 |
-
create_date: string;
|
48 |
-
create_time: number;
|
49 |
-
description: null;
|
50 |
-
dsl: {
|
51 |
-
answer: any[];
|
52 |
-
components: DSLComponentList;
|
53 |
-
graph: { nodes: Node[]; edges: Edge[] };
|
54 |
-
history: any[];
|
55 |
-
path: string[];
|
56 |
-
};
|
57 |
-
id: string;
|
58 |
-
title: string;
|
59 |
-
update_date: string;
|
60 |
-
update_time: number;
|
61 |
-
user_id: string;
|
62 |
-
}
|
|
|
1 |
+
import { FormInstance } from 'antd';
|
2 |
|
3 |
export interface DSLComponentList {
|
4 |
id: string;
|
|
|
7 |
|
8 |
export interface IOperatorForm {
|
9 |
onValuesChange?(changedValues: any, values: any): void;
|
10 |
+
form?: FormInstance;
|
11 |
}
|
12 |
|
13 |
export interface IBeginForm {
|
|
|
41 |
color: string;
|
42 |
form: IBeginForm | IRetrievalForm | IGenerateForm;
|
43 |
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
web/src/pages/flow/list/flow-card/index.tsx
CHANGED
@@ -11,7 +11,7 @@ import { useTranslation } from 'react-i18next';
|
|
11 |
import { useNavigate } from 'umi';
|
12 |
|
13 |
import { useDeleteFlow } from '@/hooks/flow-hooks';
|
14 |
-
import { IFlow } from '
|
15 |
import styles from './index.less';
|
16 |
|
17 |
interface IProps {
|
|
|
11 |
import { useNavigate } from 'umi';
|
12 |
|
13 |
import { useDeleteFlow } from '@/hooks/flow-hooks';
|
14 |
+
import { IFlow } from '@/interfaces/database/flow';
|
15 |
import styles from './index.less';
|
16 |
|
17 |
interface IProps {
|
web/src/pages/flow/list/index.tsx
CHANGED
@@ -31,8 +31,8 @@ const FlowList = () => {
|
|
31 |
<Spin spinning={loading}>
|
32 |
<Flex gap={'large'} wrap="wrap" className={styles.flowCardContainer}>
|
33 |
{list.length > 0 ? (
|
34 |
-
list.map((item
|
35 |
-
return <FlowCard item={item} key={item.
|
36 |
})
|
37 |
) : (
|
38 |
<Empty className={styles.knowledgeEmpty}></Empty>
|
|
|
31 |
<Spin spinning={loading}>
|
32 |
<Flex gap={'large'} wrap="wrap" className={styles.flowCardContainer}>
|
33 |
{list.length > 0 ? (
|
34 |
+
list.map((item) => {
|
35 |
+
return <FlowCard item={item} key={item.id}></FlowCard>;
|
36 |
})
|
37 |
) : (
|
38 |
<Empty className={styles.knowledgeEmpty}></Empty>
|
web/src/pages/flow/retrieval-form/index.tsx
CHANGED
@@ -18,9 +18,7 @@ const onFinishFailed: FormProps<FieldType>['onFinishFailed'] = (errorInfo) => {
|
|
18 |
console.log('Failed:', errorInfo);
|
19 |
};
|
20 |
|
21 |
-
const RetrievalForm = ({ onValuesChange }: IOperatorForm) => {
|
22 |
-
const [form] = Form.useForm();
|
23 |
-
|
24 |
return (
|
25 |
<Form
|
26 |
name="basic"
|
@@ -32,7 +30,10 @@ const RetrievalForm = ({ onValuesChange }: IOperatorForm) => {
|
|
32 |
onValuesChange={onValuesChange}
|
33 |
form={form}
|
34 |
>
|
35 |
-
<SimilaritySlider
|
|
|
|
|
|
|
36 |
<TopNItem></TopNItem>
|
37 |
<Rerank></Rerank>
|
38 |
<KnowledgeBaseItem></KnowledgeBaseItem>
|
|
|
18 |
console.log('Failed:', errorInfo);
|
19 |
};
|
20 |
|
21 |
+
const RetrievalForm = ({ onValuesChange, form }: IOperatorForm) => {
|
|
|
|
|
22 |
return (
|
23 |
<Form
|
24 |
name="basic"
|
|
|
30 |
onValuesChange={onValuesChange}
|
31 |
form={form}
|
32 |
>
|
33 |
+
<SimilaritySlider
|
34 |
+
isTooltipShown
|
35 |
+
vectorSimilarityWeightName="keywords_similarity_weight"
|
36 |
+
></SimilaritySlider>
|
37 |
<TopNItem></TopNItem>
|
38 |
<Rerank></Rerank>
|
39 |
<KnowledgeBaseItem></KnowledgeBaseItem>
|
web/src/pages/flow/store.ts
CHANGED
@@ -17,9 +17,6 @@ import {
|
|
17 |
import { create } from 'zustand';
|
18 |
import { devtools } from 'zustand/middleware';
|
19 |
import { NodeData } from './interface';
|
20 |
-
import { dsl } from './mock';
|
21 |
-
|
22 |
-
const { nodes: initialNodes, edges: initialEdges } = dsl.graph;
|
23 |
|
24 |
export type RFState = {
|
25 |
nodes: Node<NodeData>[];
|
@@ -41,8 +38,8 @@ export type RFState = {
|
|
41 |
// this is our useStore hook that we can use in our components to get parts of the store and call actions
|
42 |
const useStore = create<RFState>()(
|
43 |
devtools((set, get) => ({
|
44 |
-
nodes:
|
45 |
-
edges:
|
46 |
selectedNodeIds: [],
|
47 |
selectedEdgeIds: [],
|
48 |
onNodesChange: (changes: NodeChange[]) => {
|
|
|
17 |
import { create } from 'zustand';
|
18 |
import { devtools } from 'zustand/middleware';
|
19 |
import { NodeData } from './interface';
|
|
|
|
|
|
|
20 |
|
21 |
export type RFState = {
|
22 |
nodes: Node<NodeData>[];
|
|
|
38 |
// this is our useStore hook that we can use in our components to get parts of the store and call actions
|
39 |
const useStore = create<RFState>()(
|
40 |
devtools((set, get) => ({
|
41 |
+
nodes: [] as Node[],
|
42 |
+
edges: [] as Edge[],
|
43 |
selectedNodeIds: [],
|
44 |
selectedEdgeIds: [],
|
45 |
onNodesChange: (changes: NodeChange[]) => {
|
web/src/pages/flow/utils.ts
CHANGED
@@ -1,4 +1,5 @@
|
|
1 |
import { DSLComponents } from '@/interfaces/database/flow';
|
|
|
2 |
import dagre from 'dagre';
|
3 |
import { Edge, MarkerType, Node, Position } from 'reactflow';
|
4 |
import { v4 as uuidv4 } from 'uuid';
|
@@ -108,6 +109,16 @@ const buildComponentDownstreamOrUpstream = (
|
|
108 |
.map((y) => y[isBuildDownstream ? 'target' : 'source']);
|
109 |
};
|
110 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
111 |
// construct a dsl based on the node information of the graph
|
112 |
export const buildDslComponentsByGraph = (
|
113 |
nodes: Node<NodeData>[],
|
@@ -117,10 +128,15 @@ export const buildDslComponentsByGraph = (
|
|
117 |
|
118 |
nodes.forEach((x) => {
|
119 |
const id = x.id;
|
|
|
120 |
components[id] = {
|
121 |
obj: {
|
122 |
-
component_name:
|
123 |
-
params:
|
|
|
|
|
|
|
|
|
124 |
},
|
125 |
downstream: buildComponentDownstreamOrUpstream(edges, id, true),
|
126 |
upstream: buildComponentDownstreamOrUpstream(edges, id, false),
|
|
|
1 |
import { DSLComponents } from '@/interfaces/database/flow';
|
2 |
+
import { removeUselessFieldsFromValues } from '@/utils/form';
|
3 |
import dagre from 'dagre';
|
4 |
import { Edge, MarkerType, Node, Position } from 'reactflow';
|
5 |
import { v4 as uuidv4 } from 'uuid';
|
|
|
109 |
.map((y) => y[isBuildDownstream ? 'target' : 'source']);
|
110 |
};
|
111 |
|
112 |
+
const removeUselessDataInTheOperator = (
|
113 |
+
operatorName: string,
|
114 |
+
params: Record<string, unknown>,
|
115 |
+
) => {
|
116 |
+
if (operatorName === 'Generate') {
|
117 |
+
return removeUselessFieldsFromValues(params, '');
|
118 |
+
}
|
119 |
+
return params;
|
120 |
+
};
|
121 |
+
|
122 |
// construct a dsl based on the node information of the graph
|
123 |
export const buildDslComponentsByGraph = (
|
124 |
nodes: Node<NodeData>[],
|
|
|
128 |
|
129 |
nodes.forEach((x) => {
|
130 |
const id = x.id;
|
131 |
+
const operatorName = x.data.label;
|
132 |
components[id] = {
|
133 |
obj: {
|
134 |
+
component_name: operatorName,
|
135 |
+
params:
|
136 |
+
removeUselessDataInTheOperator(
|
137 |
+
operatorName,
|
138 |
+
x.data.form as Record<string, unknown>,
|
139 |
+
) ?? {},
|
140 |
},
|
141 |
downstream: buildComponentDownstreamOrUpstream(edges, id, true),
|
142 |
upstream: buildComponentDownstreamOrUpstream(edges, id, false),
|
web/src/utils/form.ts
ADDED
@@ -0,0 +1,28 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import { variableEnabledFieldMap } from '@/constants/chat';
|
2 |
+
import omit from 'lodash/omit';
|
3 |
+
|
4 |
+
// chat model setting and generate operator
|
5 |
+
export const excludeUnEnabledVariables = (
|
6 |
+
values: any,
|
7 |
+
prefix = 'llm_setting.',
|
8 |
+
) => {
|
9 |
+
const unEnabledFields: Array<keyof typeof variableEnabledFieldMap> =
|
10 |
+
Object.keys(variableEnabledFieldMap).filter((key) => !values[key]) as Array<
|
11 |
+
keyof typeof variableEnabledFieldMap
|
12 |
+
>;
|
13 |
+
|
14 |
+
return unEnabledFields.map(
|
15 |
+
(key) => `${prefix}${variableEnabledFieldMap[key]}`,
|
16 |
+
);
|
17 |
+
};
|
18 |
+
|
19 |
+
// chat model setting and generate operator
|
20 |
+
export const removeUselessFieldsFromValues = (values: any, prefix?: string) => {
|
21 |
+
const nextValues: any = omit(values, [
|
22 |
+
...Object.keys(variableEnabledFieldMap),
|
23 |
+
'parameters',
|
24 |
+
...excludeUnEnabledVariables(values, prefix),
|
25 |
+
]);
|
26 |
+
|
27 |
+
return nextValues;
|
28 |
+
};
|
web/src/utils/registerServer.ts
CHANGED
@@ -1,7 +1,10 @@
|
|
1 |
import omit from 'lodash/omit';
|
2 |
import { RequestMethod } from 'umi-request';
|
3 |
|
4 |
-
type Service<T extends string> = Record<
|
|
|
|
|
|
|
5 |
|
6 |
const registerServer = <T extends string>(
|
7 |
opt: Record<T, { url: string; method: string }>,
|
|
|
1 |
import omit from 'lodash/omit';
|
2 |
import { RequestMethod } from 'umi-request';
|
3 |
|
4 |
+
type Service<T extends string> = Record<
|
5 |
+
T,
|
6 |
+
(params?: any, urlAppendix?: string) => any
|
7 |
+
>;
|
8 |
|
9 |
const registerServer = <T extends string>(
|
10 |
opt: Record<T, { url: string; method: string }>,
|