From db35e9df4f7ebbe1d043cb690150122d6a61d5d7 Mon Sep 17 00:00:00 2001 From: balibabu Date: Thu, 6 Jun 2024 15:00:37 +0800 Subject: [PATCH] feat: run flow (#1076) ### What problem does this PR solve? feat: run flow #918 ### Type of change - [x] New Feature (non-breaking change which adds functionality) --- web/src/hooks/flow-hooks.ts | 19 ++++++++++++++ web/src/pages/flow/constant.ts | 13 +++++++--- web/src/pages/flow/header/index.tsx | 5 ++-- web/src/pages/flow/hooks.ts | 22 ++++++++++++++-- web/src/pages/flow/mock.tsx | 2 +- web/src/pages/flow/utils.ts | 39 +++++++++++++++++++++-------- web/src/services/flow-service.ts | 5 ++++ web/src/utils/api.ts | 1 + web/src/utils/form.ts | 2 +- 9 files changed, 88 insertions(+), 20 deletions(-) diff --git a/web/src/hooks/flow-hooks.ts b/web/src/hooks/flow-hooks.ts index 9fb3cfe70..7d9b74bbb 100644 --- a/web/src/hooks/flow-hooks.ts +++ b/web/src/hooks/flow-hooks.ts @@ -90,3 +90,22 @@ export const useDeleteFlow = () => { return { data, loading, deleteFlow: mutateAsync }; }; + +export const useRunFlow = () => { + const { + data, + isPending: loading, + mutateAsync, + } = useMutation({ + mutationKey: ['runFlow'], + mutationFn: async (params: { id: string; dsl: DSL }) => { + const { data } = await flowService.runCanvas(params); + if (data.retcode === 0) { + message.success(i18n.t(`message.modified`)); + } + return data?.data ?? {}; + }, + }); + + return { data, loading, runFlow: mutateAsync }; +}; diff --git a/web/src/pages/flow/constant.ts b/web/src/pages/flow/constant.ts index f230a68ba..0f29c775f 100644 --- a/web/src/pages/flow/constant.ts +++ b/web/src/pages/flow/constant.ts @@ -1,5 +1,3 @@ -import { ModelVariableType } from '@/constants/knowledge'; - export enum Operator { Begin = 'Begin', Retrieval = 'Retrieval', @@ -18,8 +16,8 @@ export const initialBeginValues = { }; export const initialGenerateValues = { - parameters: ModelVariableType.Precise, - temperatureEnabled: false, + // parameters: ModelVariableType.Precise, + // temperatureEnabled: true, temperature: 0.1, top_p: 0.3, frequency_penalty: 0.7, @@ -30,3 +28,10 @@ export const initialGenerateValues = { The above is the content you need to summarize.`, cite: true, }; + +export const initialFormValuesMap = { + [Operator.Begin]: initialBeginValues, + [Operator.Retrieval]: initialRetrievalValues, + [Operator.Generate]: initialGenerateValues, + [Operator.Answer]: {}, +}; diff --git a/web/src/pages/flow/header/index.tsx b/web/src/pages/flow/header/index.tsx index 57293ffbd..b4988c4d4 100644 --- a/web/src/pages/flow/header/index.tsx +++ b/web/src/pages/flow/header/index.tsx @@ -1,10 +1,11 @@ import { Button, Flex } from 'antd'; -import { useSaveGraph } from '../hooks'; +import { useRunGraph, useSaveGraph } from '../hooks'; import styles from './index.less'; const FlowHeader = () => { const { saveGraph } = useSaveGraph(); + const { runGraph } = useRunGraph(); return ( { gap={'large'} className={styles.flowHeader} > -