balibabu
commited on
Commit
·
8a7a5d9
1
Parent(s):
eba9007
feat: call the reset api before opening the run drawer each time #918 (#1370)
Browse files### What problem does this PR solve?
feat: call the reset api before opening the run drawer each time #918
### Type of change
- [x] New Feature (non-breaking change which adds functionality)
web/src/hooks/flow-hooks.ts
CHANGED
@@ -164,3 +164,20 @@ export const useRunFlow = () => {
|
|
164 |
|
165 |
return { data, loading, runFlow: mutateAsync };
|
166 |
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
164 |
|
165 |
return { data, loading, runFlow: mutateAsync };
|
166 |
};
|
167 |
+
|
168 |
+
export const useResetFlow = () => {
|
169 |
+
const { id } = useParams();
|
170 |
+
const {
|
171 |
+
data,
|
172 |
+
isPending: loading,
|
173 |
+
mutateAsync,
|
174 |
+
} = useMutation({
|
175 |
+
mutationKey: ['resetFlow'],
|
176 |
+
mutationFn: async () => {
|
177 |
+
const { data } = await flowService.resetCanvas({ id });
|
178 |
+
return data;
|
179 |
+
},
|
180 |
+
});
|
181 |
+
|
182 |
+
return { data, loading, resetFlow: mutateAsync };
|
183 |
+
};
|
web/src/pages/flow/canvas/node/index.tsx
CHANGED
@@ -39,7 +39,12 @@ export function RagNode({
|
|
39 |
id="b"
|
40 |
></Handle>
|
41 |
<Handle type="source" position={Position.Bottom} id="a" isConnectable />
|
42 |
-
<Flex
|
|
|
|
|
|
|
|
|
|
|
43 |
<OperatorIcon
|
44 |
name={data.label as Operator}
|
45 |
fontSize={style['iconFontSize'] ?? 24}
|
@@ -48,7 +53,7 @@ export function RagNode({
|
|
48 |
className={styles.type}
|
49 |
style={{ fontSize: style.fontSize ?? 14 }}
|
50 |
>
|
51 |
-
{data.label}
|
52 |
</span>
|
53 |
<NodeDropdown id={id}></NodeDropdown>
|
54 |
</Flex>
|
|
|
39 |
id="b"
|
40 |
></Handle>
|
41 |
<Handle type="source" position={Position.Bottom} id="a" isConnectable />
|
42 |
+
<Flex
|
43 |
+
vertical
|
44 |
+
align="center"
|
45 |
+
justify={'center'}
|
46 |
+
gap={data.label === Operator.RewriteQuestion ? 0 : 6}
|
47 |
+
>
|
48 |
<OperatorIcon
|
49 |
name={data.label as Operator}
|
50 |
fontSize={style['iconFontSize'] ?? 24}
|
|
|
53 |
className={styles.type}
|
54 |
style={{ fontSize: style.fontSize ?? 14 }}
|
55 |
>
|
56 |
+
{data.label === Operator.RewriteQuestion ? 'Rewrite' : data.label}
|
57 |
</span>
|
58 |
<NodeDropdown id={id}></NodeDropdown>
|
59 |
</Flex>
|
web/src/pages/flow/chat/hooks.ts
CHANGED
@@ -1,5 +1,5 @@
|
|
1 |
import { MessageType } from '@/constants/chat';
|
2 |
-
import { useFetchFlow } from '@/hooks/flow-hooks';
|
3 |
import {
|
4 |
useHandleMessageInputChange,
|
5 |
useScrollToBottom,
|
@@ -93,13 +93,13 @@ export const useSendMessage = (
|
|
93 |
) => {
|
94 |
const { id: flowId } = useParams();
|
95 |
const { handleInputChange, value, setValue } = useHandleMessageInputChange();
|
96 |
-
const {
|
97 |
-
const
|
98 |
|
99 |
const { send, answer, done } = useSendMessageWithSse(api.runCanvas);
|
100 |
|
101 |
const sendMessage = useCallback(
|
102 |
-
async (message: string
|
103 |
const params: Record<string, unknown> = {
|
104 |
id: flowId,
|
105 |
};
|
@@ -128,6 +128,18 @@ export const useSendMessage = (
|
|
128 |
[sendMessage],
|
129 |
);
|
130 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
131 |
useEffect(() => {
|
132 |
if (answer.answer) {
|
133 |
addNewestAnswer(answer);
|
@@ -135,11 +147,8 @@ export const useSendMessage = (
|
|
135 |
}, [answer, addNewestAnswer]);
|
136 |
|
137 |
useEffect(() => {
|
138 |
-
|
139 |
-
|
140 |
-
sendMessage('');
|
141 |
-
}
|
142 |
-
}, [sendMessage, messages]);
|
143 |
|
144 |
const handlePressEnter = useCallback(() => {
|
145 |
if (done) {
|
|
|
1 |
import { MessageType } from '@/constants/chat';
|
2 |
+
import { useFetchFlow, useResetFlow } from '@/hooks/flow-hooks';
|
3 |
import {
|
4 |
useHandleMessageInputChange,
|
5 |
useScrollToBottom,
|
|
|
93 |
) => {
|
94 |
const { id: flowId } = useParams();
|
95 |
const { handleInputChange, value, setValue } = useHandleMessageInputChange();
|
96 |
+
const { refetch } = useFetchFlow();
|
97 |
+
const { resetFlow } = useResetFlow();
|
98 |
|
99 |
const { send, answer, done } = useSendMessageWithSse(api.runCanvas);
|
100 |
|
101 |
const sendMessage = useCallback(
|
102 |
+
async (message: string) => {
|
103 |
const params: Record<string, unknown> = {
|
104 |
id: flowId,
|
105 |
};
|
|
|
128 |
[sendMessage],
|
129 |
);
|
130 |
|
131 |
+
/**
|
132 |
+
* Call the reset api before opening the run drawer each time
|
133 |
+
*/
|
134 |
+
const resetFlowBeforeFetchingPrologue = useCallback(async () => {
|
135 |
+
// After resetting, all previous messages will be cleared.
|
136 |
+
const ret = await resetFlow();
|
137 |
+
if (ret.retcode === 0) {
|
138 |
+
// fetch prologue
|
139 |
+
sendMessage('');
|
140 |
+
}
|
141 |
+
}, [resetFlow, sendMessage]);
|
142 |
+
|
143 |
useEffect(() => {
|
144 |
if (answer.answer) {
|
145 |
addNewestAnswer(answer);
|
|
|
147 |
}, [answer, addNewestAnswer]);
|
148 |
|
149 |
useEffect(() => {
|
150 |
+
resetFlowBeforeFetchingPrologue();
|
151 |
+
}, [resetFlowBeforeFetchingPrologue]);
|
|
|
|
|
|
|
152 |
|
153 |
const handlePressEnter = useCallback(() => {
|
154 |
if (done) {
|
web/src/pages/flow/constant.tsx
CHANGED
@@ -1,9 +1,9 @@
|
|
1 |
import {
|
2 |
BranchesOutlined,
|
3 |
DatabaseOutlined,
|
|
|
4 |
MergeCellsOutlined,
|
5 |
MessageOutlined,
|
6 |
-
QuestionOutlined,
|
7 |
RocketOutlined,
|
8 |
SendOutlined,
|
9 |
SlidersOutlined,
|
@@ -28,7 +28,7 @@ export const operatorIconMap = {
|
|
28 |
[Operator.Categorize]: DatabaseOutlined,
|
29 |
[Operator.Message]: MessageOutlined,
|
30 |
[Operator.Relevant]: BranchesOutlined,
|
31 |
-
[Operator.RewriteQuestion]:
|
32 |
};
|
33 |
|
34 |
export const operatorMap = {
|
@@ -76,7 +76,12 @@ export const operatorMap = {
|
|
76 |
},
|
77 |
[Operator.RewriteQuestion]: {
|
78 |
description: 'RewriteQuestion description',
|
79 |
-
backgroundColor: '
|
|
|
|
|
|
|
|
|
|
|
80 |
},
|
81 |
};
|
82 |
|
|
|
1 |
import {
|
2 |
BranchesOutlined,
|
3 |
DatabaseOutlined,
|
4 |
+
FormOutlined,
|
5 |
MergeCellsOutlined,
|
6 |
MessageOutlined,
|
|
|
7 |
RocketOutlined,
|
8 |
SendOutlined,
|
9 |
SlidersOutlined,
|
|
|
28 |
[Operator.Categorize]: DatabaseOutlined,
|
29 |
[Operator.Message]: MessageOutlined,
|
30 |
[Operator.Relevant]: BranchesOutlined,
|
31 |
+
[Operator.RewriteQuestion]: FormOutlined,
|
32 |
};
|
33 |
|
34 |
export const operatorMap = {
|
|
|
76 |
},
|
77 |
[Operator.RewriteQuestion]: {
|
78 |
description: 'RewriteQuestion description',
|
79 |
+
backgroundColor: '#f8c7f8',
|
80 |
+
color: 'white',
|
81 |
+
width: 70,
|
82 |
+
height: 70,
|
83 |
+
fontSize: 12,
|
84 |
+
iconFontSize: 16,
|
85 |
},
|
86 |
};
|
87 |
|
web/src/pages/flow/header/index.tsx
CHANGED
@@ -32,7 +32,7 @@ const FlowHeader = ({ showChatDrawer }: IProps) => {
|
|
32 |
</Space>
|
33 |
<Space size={'large'}>
|
34 |
<Button onClick={showChatDrawer}>
|
35 |
-
<b>
|
36 |
</Button>
|
37 |
<Button type="primary" onClick={saveGraph}>
|
38 |
<b>Save</b>
|
|
|
32 |
</Space>
|
33 |
<Space size={'large'}>
|
34 |
<Button onClick={showChatDrawer}>
|
35 |
+
<b>Run</b>
|
36 |
</Button>
|
37 |
<Button type="primary" onClick={saveGraph}>
|
38 |
<b>Save</b>
|