balibabu
commited on
Commit
·
454aa85
1
Parent(s):
09502ac
feat: add icon to graph nodes #918 (#1117)
Browse files### What problem does this PR solve?
feat: add icon to graph nodes #918
### Type of change
- [x] New Feature (non-breaking change which adds functionality)
- web/src/pages/chat/hooks.ts +7 -12
- web/src/pages/chat/shared-hooks.ts +2 -7
- web/src/pages/flow/canvas/node/index.tsx +14 -3
- web/src/pages/flow/chat/hooks.ts +1 -1
- web/src/pages/flow/constant.tsx +20 -3
- web/src/pages/flow/flow-sider/index.tsx +27 -20
- web/src/pages/flow/operator-icon/index.less +4 -0
- web/src/pages/flow/operator-icon/index.tsx +16 -0
web/src/pages/chat/hooks.ts
CHANGED
|
@@ -552,14 +552,12 @@ export const useSendMessage = (
|
|
| 552 |
const { conversationId } = useGetChatSearchParams();
|
| 553 |
const { handleInputChange, value, setValue } = useHandleMessageInputChange();
|
| 554 |
|
| 555 |
-
const fetchConversation = useFetchConversation();
|
| 556 |
-
|
| 557 |
const { handleClickConversation } = useClickConversationCard();
|
| 558 |
const { send, answer, done } = useSendMessageWithSse();
|
| 559 |
|
| 560 |
const sendMessage = useCallback(
|
| 561 |
async (message: string, id?: string) => {
|
| 562 |
-
const res
|
| 563 |
conversation_id: id ?? conversationId,
|
| 564 |
messages: [
|
| 565 |
...(conversation?.message ?? []).map((x: IMessage) => omit(x, 'id')),
|
|
@@ -570,7 +568,12 @@ export const useSendMessage = (
|
|
| 570 |
],
|
| 571 |
});
|
| 572 |
|
| 573 |
-
if (res.status
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 574 |
if (id) {
|
| 575 |
console.info('111');
|
| 576 |
// new conversation
|
|
@@ -579,15 +582,7 @@ export const useSendMessage = (
|
|
| 579 |
console.info('222');
|
| 580 |
// fetchConversation(conversationId);
|
| 581 |
}
|
| 582 |
-
} else {
|
| 583 |
-
console.info('333');
|
| 584 |
-
|
| 585 |
-
// cancel loading
|
| 586 |
-
setValue(message);
|
| 587 |
-
console.info('removeLatestMessage111');
|
| 588 |
-
removeLatestMessage();
|
| 589 |
}
|
| 590 |
-
console.info('false');
|
| 591 |
},
|
| 592 |
[
|
| 593 |
conversation?.message,
|
|
|
|
| 552 |
const { conversationId } = useGetChatSearchParams();
|
| 553 |
const { handleInputChange, value, setValue } = useHandleMessageInputChange();
|
| 554 |
|
|
|
|
|
|
|
| 555 |
const { handleClickConversation } = useClickConversationCard();
|
| 556 |
const { send, answer, done } = useSendMessageWithSse();
|
| 557 |
|
| 558 |
const sendMessage = useCallback(
|
| 559 |
async (message: string, id?: string) => {
|
| 560 |
+
const res = await send({
|
| 561 |
conversation_id: id ?? conversationId,
|
| 562 |
messages: [
|
| 563 |
...(conversation?.message ?? []).map((x: IMessage) => omit(x, 'id')),
|
|
|
|
| 568 |
],
|
| 569 |
});
|
| 570 |
|
| 571 |
+
if (res && (res?.response.status !== 200 || res?.data?.retcode !== 0)) {
|
| 572 |
+
// cancel loading
|
| 573 |
+
setValue(message);
|
| 574 |
+
console.info('removeLatestMessage111');
|
| 575 |
+
removeLatestMessage();
|
| 576 |
+
} else {
|
| 577 |
if (id) {
|
| 578 |
console.info('111');
|
| 579 |
// new conversation
|
|
|
|
| 582 |
console.info('222');
|
| 583 |
// fetchConversation(conversationId);
|
| 584 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 585 |
}
|
|
|
|
| 586 |
},
|
| 587 |
[
|
| 588 |
conversation?.message,
|
web/src/pages/chat/shared-hooks.ts
CHANGED
|
@@ -150,7 +150,7 @@ export const useSendSharedMessage = (
|
|
| 150 |
|
| 151 |
const sendMessage = useCallback(
|
| 152 |
async (message: string, id?: string) => {
|
| 153 |
-
const res
|
| 154 |
conversation_id: id ?? conversationId,
|
| 155 |
quote: false,
|
| 156 |
messages: [
|
|
@@ -162,12 +162,7 @@ export const useSendSharedMessage = (
|
|
| 162 |
],
|
| 163 |
});
|
| 164 |
|
| 165 |
-
if (res?.status
|
| 166 |
-
// const data = await fetchConversation(conversationId);
|
| 167 |
-
// if (data.retcode === 0) {
|
| 168 |
-
// setCurrentConversation(data.data);
|
| 169 |
-
// }
|
| 170 |
-
} else {
|
| 171 |
// cancel loading
|
| 172 |
setValue(message);
|
| 173 |
removeLatestMessage();
|
|
|
|
| 150 |
|
| 151 |
const sendMessage = useCallback(
|
| 152 |
async (message: string, id?: string) => {
|
| 153 |
+
const res = await send({
|
| 154 |
conversation_id: id ?? conversationId,
|
| 155 |
quote: false,
|
| 156 |
messages: [
|
|
|
|
| 162 |
],
|
| 163 |
});
|
| 164 |
|
| 165 |
+
if (res && (res?.response.status !== 200 || res?.data?.retcode !== 0)) {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 166 |
// cancel loading
|
| 167 |
setValue(message);
|
| 168 |
removeLatestMessage();
|
web/src/pages/flow/canvas/node/index.tsx
CHANGED
|
@@ -1,6 +1,9 @@
|
|
| 1 |
import classNames from 'classnames';
|
| 2 |
import { Handle, NodeProps, Position } from 'reactflow';
|
| 3 |
|
|
|
|
|
|
|
|
|
|
| 4 |
import styles from './index.less';
|
| 5 |
|
| 6 |
export function TextUpdaterNode({
|
|
@@ -9,7 +12,7 @@ export function TextUpdaterNode({
|
|
| 9 |
selected,
|
| 10 |
}: NodeProps<{ label: string }>) {
|
| 11 |
return (
|
| 12 |
-
<
|
| 13 |
className={classNames(styles.textUpdaterNode, {
|
| 14 |
[styles.selectedNode]: selected,
|
| 15 |
})}
|
|
@@ -30,7 +33,15 @@ export function TextUpdaterNode({
|
|
| 30 |
>
|
| 31 |
{/* <PlusCircleOutlined style={{ fontSize: 10 }} /> */}
|
| 32 |
</Handle>
|
| 33 |
-
<div>
|
| 34 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 35 |
);
|
| 36 |
}
|
|
|
|
| 1 |
import classNames from 'classnames';
|
| 2 |
import { Handle, NodeProps, Position } from 'reactflow';
|
| 3 |
|
| 4 |
+
import { Space } from 'antd';
|
| 5 |
+
import { Operator } from '../../constant';
|
| 6 |
+
import OperatorIcon from '../../operator-icon';
|
| 7 |
import styles from './index.less';
|
| 8 |
|
| 9 |
export function TextUpdaterNode({
|
|
|
|
| 12 |
selected,
|
| 13 |
}: NodeProps<{ label: string }>) {
|
| 14 |
return (
|
| 15 |
+
<section
|
| 16 |
className={classNames(styles.textUpdaterNode, {
|
| 17 |
[styles.selectedNode]: selected,
|
| 18 |
})}
|
|
|
|
| 33 |
>
|
| 34 |
{/* <PlusCircleOutlined style={{ fontSize: 10 }} /> */}
|
| 35 |
</Handle>
|
| 36 |
+
<div>
|
| 37 |
+
<Space>
|
| 38 |
+
<OperatorIcon
|
| 39 |
+
name={data.label as Operator}
|
| 40 |
+
fontSize={12}
|
| 41 |
+
></OperatorIcon>
|
| 42 |
+
{data.label}
|
| 43 |
+
</Space>
|
| 44 |
+
</div>
|
| 45 |
+
</section>
|
| 46 |
);
|
| 47 |
}
|
web/src/pages/flow/chat/hooks.ts
CHANGED
|
@@ -112,7 +112,7 @@ export const useSendMessage = (
|
|
| 112 |
}
|
| 113 |
const res = await send(params);
|
| 114 |
|
| 115 |
-
if (res?.response.status !== 200 || res?.data?.retcode !== 0) {
|
| 116 |
antMessage.error(res?.data?.retmsg);
|
| 117 |
|
| 118 |
// cancel loading
|
|
|
|
| 112 |
}
|
| 113 |
const res = await send(params);
|
| 114 |
|
| 115 |
+
if (res && (res?.response.status !== 200 || res?.data?.retcode !== 0)) {
|
| 116 |
antMessage.error(res?.data?.retmsg);
|
| 117 |
|
| 118 |
// cancel loading
|
web/src/pages/flow/constant.tsx
CHANGED
|
@@ -2,6 +2,7 @@ import {
|
|
| 2 |
MergeCellsOutlined,
|
| 3 |
RocketOutlined,
|
| 4 |
SendOutlined,
|
|
|
|
| 5 |
} from '@ant-design/icons';
|
| 6 |
|
| 7 |
export enum Operator {
|
|
@@ -11,10 +12,26 @@ export enum Operator {
|
|
| 11 |
Answer = 'Answer',
|
| 12 |
}
|
| 13 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 14 |
export const componentList = [
|
| 15 |
-
{
|
| 16 |
-
|
| 17 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 18 |
];
|
| 19 |
|
| 20 |
export const initialRetrievalValues = {
|
|
|
|
| 2 |
MergeCellsOutlined,
|
| 3 |
RocketOutlined,
|
| 4 |
SendOutlined,
|
| 5 |
+
SlidersOutlined,
|
| 6 |
} from '@ant-design/icons';
|
| 7 |
|
| 8 |
export enum Operator {
|
|
|
|
| 12 |
Answer = 'Answer',
|
| 13 |
}
|
| 14 |
|
| 15 |
+
export const operatorIconMap = {
|
| 16 |
+
[Operator.Retrieval]: RocketOutlined,
|
| 17 |
+
[Operator.Generate]: MergeCellsOutlined,
|
| 18 |
+
[Operator.Answer]: SendOutlined,
|
| 19 |
+
[Operator.Begin]: SlidersOutlined,
|
| 20 |
+
};
|
| 21 |
+
|
| 22 |
export const componentList = [
|
| 23 |
+
{
|
| 24 |
+
name: Operator.Retrieval,
|
| 25 |
+
description: '',
|
| 26 |
+
},
|
| 27 |
+
{
|
| 28 |
+
name: Operator.Generate,
|
| 29 |
+
description: '',
|
| 30 |
+
},
|
| 31 |
+
{
|
| 32 |
+
name: Operator.Answer,
|
| 33 |
+
description: '',
|
| 34 |
+
},
|
| 35 |
];
|
| 36 |
|
| 37 |
export const initialRetrievalValues = {
|
web/src/pages/flow/flow-sider/index.tsx
CHANGED
|
@@ -1,8 +1,9 @@
|
|
| 1 |
-
import {
|
| 2 |
import classNames from 'classnames';
|
| 3 |
|
| 4 |
import { componentList } from '../constant';
|
| 5 |
import { useHandleDrag } from '../hooks';
|
|
|
|
| 6 |
import styles from './index.less';
|
| 7 |
|
| 8 |
const { Sider } = Layout;
|
|
@@ -24,25 +25,31 @@ const FlowSide = ({ setCollapsed, collapsed }: IProps) => {
|
|
| 24 |
onCollapse={(value) => setCollapsed(value)}
|
| 25 |
>
|
| 26 |
<Flex vertical gap={10} className={styles.siderContent}>
|
| 27 |
-
{componentList.map((x) =>
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
<
|
| 37 |
-
<
|
| 38 |
-
|
| 39 |
-
<
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 46 |
</Flex>
|
| 47 |
</Sider>
|
| 48 |
);
|
|
|
|
| 1 |
+
import { Card, Flex, Layout, Space } from 'antd';
|
| 2 |
import classNames from 'classnames';
|
| 3 |
|
| 4 |
import { componentList } from '../constant';
|
| 5 |
import { useHandleDrag } from '../hooks';
|
| 6 |
+
import OperatorIcon from '../operator-icon';
|
| 7 |
import styles from './index.less';
|
| 8 |
|
| 9 |
const { Sider } = Layout;
|
|
|
|
| 25 |
onCollapse={(value) => setCollapsed(value)}
|
| 26 |
>
|
| 27 |
<Flex vertical gap={10} className={styles.siderContent}>
|
| 28 |
+
{componentList.map((x) => {
|
| 29 |
+
return (
|
| 30 |
+
<Card
|
| 31 |
+
key={x.name}
|
| 32 |
+
hoverable
|
| 33 |
+
draggable
|
| 34 |
+
className={classNames(styles.operatorCard)}
|
| 35 |
+
onDragStart={handleDragStart(x.name)}
|
| 36 |
+
>
|
| 37 |
+
<Flex justify="space-between" align="center">
|
| 38 |
+
<Space size={15}>
|
| 39 |
+
<OperatorIcon name={x.name}></OperatorIcon>
|
| 40 |
+
{/* <Avatar
|
| 41 |
+
icon={<OperatorIcon name={x.name}></OperatorIcon>}
|
| 42 |
+
shape={'square'}
|
| 43 |
+
/> */}
|
| 44 |
+
<section>
|
| 45 |
+
<b>{x.name}</b>
|
| 46 |
+
<div>{x.description}</div>
|
| 47 |
+
</section>
|
| 48 |
+
</Space>
|
| 49 |
+
</Flex>
|
| 50 |
+
</Card>
|
| 51 |
+
);
|
| 52 |
+
})}
|
| 53 |
</Flex>
|
| 54 |
</Sider>
|
| 55 |
);
|
web/src/pages/flow/operator-icon/index.less
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
.icon {
|
| 2 |
+
color: rgb(59, 118, 244);
|
| 3 |
+
font-size: 24px;
|
| 4 |
+
}
|
web/src/pages/flow/operator-icon/index.tsx
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import React from 'react';
|
| 2 |
+
import { Operator, operatorIconMap } from '../constant';
|
| 3 |
+
|
| 4 |
+
import styles from './index.less';
|
| 5 |
+
|
| 6 |
+
interface IProps {
|
| 7 |
+
name: Operator;
|
| 8 |
+
fontSize?: number;
|
| 9 |
+
}
|
| 10 |
+
|
| 11 |
+
const OperatorIcon = ({ name, fontSize }: IProps) => {
|
| 12 |
+
const Icon = operatorIconMap[name] || React.Fragment;
|
| 13 |
+
return <Icon className={styles.icon} style={{ fontSize }}></Icon>;
|
| 14 |
+
};
|
| 15 |
+
|
| 16 |
+
export default OperatorIcon;
|