balibabu
commited on
Commit
·
405c9f9
1
Parent(s):
279ca43
feat: Add Skeleton to MessageItem before the backend returns a message and fixed the issue where ChatConfigurationModal displays old data when creating a new dialog (#99)
Browse files* feat: fixed the issue where ChatConfigurationModal displays old data when creating a new dialog
* feat: Add Skeleton to MessageItem before the backend returns a message
- web/.umirc.ts +1 -1
- web/src/layouts/components/header/index.tsx +1 -2
- web/src/less/index.less +2 -0
- web/src/less/mixins.less +31 -0
- web/src/pages/add-knowledge/components/knowledge-chunk/components/chunk-card/index.less +1 -29
- web/src/pages/chat/chat-configuration-modal/index.tsx +9 -7
- web/src/pages/chat/chat-container/index.less +6 -0
- web/src/pages/chat/chat-container/index.tsx +25 -12
- web/src/pages/chat/hooks.ts +29 -11
- web/src/pages/chat/index.less +1 -0
- web/src/pages/chat/index.tsx +3 -3
- web/src/pages/chat/model.ts +9 -8
web/.umirc.ts
CHANGED
|
@@ -18,7 +18,7 @@ export default defineConfig({
|
|
| 18 |
dva: {},
|
| 19 |
lessLoader: {
|
| 20 |
modifyVars: {
|
| 21 |
-
hack: `true; @import "~@/less/
|
| 22 |
},
|
| 23 |
},
|
| 24 |
proxy: {
|
|
|
|
| 18 |
dva: {},
|
| 19 |
lessLoader: {
|
| 20 |
modifyVars: {
|
| 21 |
+
hack: `true; @import "~@/less/index.less";`,
|
| 22 |
},
|
| 23 |
},
|
| 24 |
proxy: {
|
web/src/layouts/components/header/index.tsx
CHANGED
|
@@ -1,5 +1,4 @@
|
|
| 1 |
import { ReactComponent as StarIon } from '@/assets/svg/chat-star.svg';
|
| 2 |
-
import { ReactComponent as FileIcon } from '@/assets/svg/file-management.svg';
|
| 3 |
import { ReactComponent as KnowledgeBaseIcon } from '@/assets/svg/knowledge-base.svg';
|
| 4 |
import { ReactComponent as Logo } from '@/assets/svg/logo.svg';
|
| 5 |
import { Layout, Radio, Space, theme } from 'antd';
|
|
@@ -23,7 +22,7 @@ const RagHeader = () => {
|
|
| 23 |
() => [
|
| 24 |
{ path: '/knowledge', name: 'Knowledge Base', icon: KnowledgeBaseIcon },
|
| 25 |
{ path: '/chat', name: 'Chat', icon: StarIon },
|
| 26 |
-
{ path: '/file', name: 'File Management', icon: FileIcon },
|
| 27 |
],
|
| 28 |
[],
|
| 29 |
);
|
|
|
|
| 1 |
import { ReactComponent as StarIon } from '@/assets/svg/chat-star.svg';
|
|
|
|
| 2 |
import { ReactComponent as KnowledgeBaseIcon } from '@/assets/svg/knowledge-base.svg';
|
| 3 |
import { ReactComponent as Logo } from '@/assets/svg/logo.svg';
|
| 4 |
import { Layout, Radio, Space, theme } from 'antd';
|
|
|
|
| 22 |
() => [
|
| 23 |
{ path: '/knowledge', name: 'Knowledge Base', icon: KnowledgeBaseIcon },
|
| 24 |
{ path: '/chat', name: 'Chat', icon: StarIon },
|
| 25 |
+
// { path: '/file', name: 'File Management', icon: FileIcon },
|
| 26 |
],
|
| 27 |
[],
|
| 28 |
);
|
web/src/less/index.less
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
|
|
|
| 1 |
+
@import './variable.less';
|
| 2 |
+
@import './mixins.less';
|
web/src/less/mixins.less
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
.chunkText() {
|
| 2 |
+
em {
|
| 3 |
+
color: red;
|
| 4 |
+
font-style: normal;
|
| 5 |
+
}
|
| 6 |
+
table {
|
| 7 |
+
width: 100%;
|
| 8 |
+
}
|
| 9 |
+
|
| 10 |
+
caption {
|
| 11 |
+
color: @blurBackground;
|
| 12 |
+
font-size: 20px;
|
| 13 |
+
height: 50px;
|
| 14 |
+
line-height: 50px;
|
| 15 |
+
font-weight: 600;
|
| 16 |
+
margin-bottom: 10px;
|
| 17 |
+
}
|
| 18 |
+
|
| 19 |
+
th {
|
| 20 |
+
color: #fff;
|
| 21 |
+
background-color: @blurBackground;
|
| 22 |
+
}
|
| 23 |
+
|
| 24 |
+
td:hover {
|
| 25 |
+
background: @blurBackgroundHover;
|
| 26 |
+
}
|
| 27 |
+
|
| 28 |
+
tr:nth-child(even) {
|
| 29 |
+
background-color: #f2f2f2;
|
| 30 |
+
}
|
| 31 |
+
}
|
web/src/pages/add-knowledge/components/knowledge-chunk/components/chunk-card/index.less
CHANGED
|
@@ -9,35 +9,7 @@
|
|
| 9 |
|
| 10 |
.content {
|
| 11 |
flex: 1;
|
| 12 |
-
|
| 13 |
-
color: red;
|
| 14 |
-
font-style: normal;
|
| 15 |
-
}
|
| 16 |
-
table {
|
| 17 |
-
width: 100%;
|
| 18 |
-
}
|
| 19 |
-
|
| 20 |
-
caption {
|
| 21 |
-
color: @blurBackground;
|
| 22 |
-
font-size: 20px;
|
| 23 |
-
height: 50px;
|
| 24 |
-
line-height: 50px;
|
| 25 |
-
font-weight: 600;
|
| 26 |
-
margin-bottom: 10px;
|
| 27 |
-
}
|
| 28 |
-
|
| 29 |
-
th {
|
| 30 |
-
color: #fff;
|
| 31 |
-
background-color: @blurBackground;
|
| 32 |
-
}
|
| 33 |
-
|
| 34 |
-
td:hover {
|
| 35 |
-
background: @blurBackgroundHover;
|
| 36 |
-
}
|
| 37 |
-
|
| 38 |
-
tr:nth-child(even) {
|
| 39 |
-
background-color: #f2f2f2;
|
| 40 |
-
}
|
| 41 |
}
|
| 42 |
|
| 43 |
.cardSelected {
|
|
|
|
| 9 |
|
| 10 |
.content {
|
| 11 |
flex: 1;
|
| 12 |
+
.chunkText;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 13 |
}
|
| 14 |
|
| 15 |
.cardSelected {
|
web/src/pages/chat/chat-configuration-modal/index.tsx
CHANGED
|
@@ -121,14 +121,16 @@ const ChatConfigurationModal = ({ visible, hideModal, id }: IProps) => {
|
|
| 121 |
);
|
| 122 |
|
| 123 |
useEffect(() => {
|
| 124 |
-
|
| 125 |
-
|
| 126 |
-
|
| 127 |
-
|
| 128 |
-
|
|
|
|
|
|
|
|
|
|
| 129 |
}
|
| 130 |
-
|
| 131 |
-
}, [currentDialog, form]);
|
| 132 |
|
| 133 |
return (
|
| 134 |
<Modal
|
|
|
|
| 121 |
);
|
| 122 |
|
| 123 |
useEffect(() => {
|
| 124 |
+
if (visible) {
|
| 125 |
+
const icon = currentDialog.icon;
|
| 126 |
+
let fileList: UploadFile[] = [];
|
| 127 |
+
|
| 128 |
+
if (icon) {
|
| 129 |
+
fileList = [{ uid: '1', name: 'file', thumbUrl: icon, status: 'done' }];
|
| 130 |
+
}
|
| 131 |
+
form.setFieldsValue({ ...currentDialog, icon: fileList });
|
| 132 |
}
|
| 133 |
+
}, [currentDialog, form, visible]);
|
|
|
|
| 134 |
|
| 135 |
return (
|
| 136 |
<Modal
|
web/src/pages/chat/chat-container/index.less
CHANGED
|
@@ -28,6 +28,9 @@
|
|
| 28 |
padding: 0 14px;
|
| 29 |
background-color: rgba(249, 250, 251, 1);
|
| 30 |
}
|
|
|
|
|
|
|
|
|
|
| 31 |
.referenceIcon {
|
| 32 |
padding: 0 6px;
|
| 33 |
}
|
|
@@ -52,3 +55,6 @@
|
|
| 52 |
.referenceImagePreview {
|
| 53 |
width: 600px;
|
| 54 |
}
|
|
|
|
|
|
|
|
|
|
|
|
| 28 |
padding: 0 14px;
|
| 29 |
background-color: rgba(249, 250, 251, 1);
|
| 30 |
}
|
| 31 |
+
.messageEmpty {
|
| 32 |
+
width: 300px;
|
| 33 |
+
}
|
| 34 |
.referenceIcon {
|
| 35 |
padding: 0 6px;
|
| 36 |
}
|
|
|
|
| 55 |
.referenceImagePreview {
|
| 56 |
width: 600px;
|
| 57 |
}
|
| 58 |
+
.chunkContentText {
|
| 59 |
+
.chunkText;
|
| 60 |
+
}
|
web/src/pages/chat/chat-container/index.tsx
CHANGED
|
@@ -11,6 +11,7 @@ import {
|
|
| 11 |
Input,
|
| 12 |
List,
|
| 13 |
Popover,
|
|
|
|
| 14 |
Space,
|
| 15 |
} from 'antd';
|
| 16 |
import classNames from 'classnames';
|
|
@@ -100,7 +101,12 @@ const MessageItem = ({
|
|
| 100 |
></Image>
|
| 101 |
</Popover>
|
| 102 |
<Space direction={'vertical'}>
|
| 103 |
-
<div
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 104 |
{documentId && (
|
| 105 |
<Flex gap={'middle'}>
|
| 106 |
<img src={fileThumbnails[documentId]} alt="" />
|
|
@@ -171,17 +177,24 @@ const MessageItem = ({
|
|
| 171 |
<Flex vertical gap={8} flex={1}>
|
| 172 |
<b>{isAssistant ? '' : userInfo.nickname}</b>
|
| 173 |
<div className={styles.messageText}>
|
| 174 |
-
|
| 175 |
-
|
| 176 |
-
|
| 177 |
-
{
|
| 178 |
-
|
| 179 |
-
|
| 180 |
-
|
| 181 |
-
|
| 182 |
-
|
| 183 |
-
|
| 184 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 185 |
</div>
|
| 186 |
{isAssistant && referenceDocumentList.length > 0 && (
|
| 187 |
<List
|
|
|
|
| 11 |
Input,
|
| 12 |
List,
|
| 13 |
Popover,
|
| 14 |
+
Skeleton,
|
| 15 |
Space,
|
| 16 |
} from 'antd';
|
| 17 |
import classNames from 'classnames';
|
|
|
|
| 101 |
></Image>
|
| 102 |
</Popover>
|
| 103 |
<Space direction={'vertical'}>
|
| 104 |
+
<div
|
| 105 |
+
dangerouslySetInnerHTML={{
|
| 106 |
+
__html: chunkItem?.content_with_weight,
|
| 107 |
+
}}
|
| 108 |
+
className={styles.chunkContentText}
|
| 109 |
+
></div>
|
| 110 |
{documentId && (
|
| 111 |
<Flex gap={'middle'}>
|
| 112 |
<img src={fileThumbnails[documentId]} alt="" />
|
|
|
|
| 177 |
<Flex vertical gap={8} flex={1}>
|
| 178 |
<b>{isAssistant ? '' : userInfo.nickname}</b>
|
| 179 |
<div className={styles.messageText}>
|
| 180 |
+
{item.content ? (
|
| 181 |
+
<Markdown
|
| 182 |
+
rehypePlugins={[rehypeWrapReference]}
|
| 183 |
+
components={
|
| 184 |
+
{
|
| 185 |
+
'custom-typography': ({
|
| 186 |
+
children,
|
| 187 |
+
}: {
|
| 188 |
+
children: string;
|
| 189 |
+
}) => renderReference(children),
|
| 190 |
+
} as any
|
| 191 |
+
}
|
| 192 |
+
>
|
| 193 |
+
{item.content}
|
| 194 |
+
</Markdown>
|
| 195 |
+
) : (
|
| 196 |
+
<Skeleton active className={styles.messageEmpty} />
|
| 197 |
+
)}
|
| 198 |
</div>
|
| 199 |
{isAssistant && referenceDocumentList.length > 0 && (
|
| 200 |
<List
|
web/src/pages/chat/hooks.ts
CHANGED
|
@@ -78,12 +78,10 @@ export const useSetCurrentDialog = () => {
|
|
| 78 |
|
| 79 |
const setCurrentDialog = useCallback(
|
| 80 |
(dialogId: string) => {
|
| 81 |
-
|
| 82 |
-
|
| 83 |
-
|
| 84 |
-
|
| 85 |
-
});
|
| 86 |
-
}
|
| 87 |
},
|
| 88 |
[dispatch],
|
| 89 |
);
|
|
@@ -427,6 +425,12 @@ export const useSelectCurrentConversation = () => {
|
|
| 427 |
content: message,
|
| 428 |
id: uuid(),
|
| 429 |
} as IMessage,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 430 |
],
|
| 431 |
};
|
| 432 |
});
|
|
@@ -525,12 +529,13 @@ export const useSendMessage = () => {
|
|
| 525 |
const conversation: IClientConversation = useSelector(
|
| 526 |
(state: any) => state.chatModel.currentConversation,
|
| 527 |
);
|
|
|
|
| 528 |
|
| 529 |
const { handleClickConversation } = useClickConversationCard();
|
| 530 |
|
| 531 |
const sendMessage = useCallback(
|
| 532 |
-
(message: string, id?: string) => {
|
| 533 |
-
dispatch({
|
| 534 |
type: 'chatModel/completeConversation',
|
| 535 |
payload: {
|
| 536 |
conversation_id: id ?? conversationId,
|
|
@@ -545,8 +550,22 @@ export const useSendMessage = () => {
|
|
| 545 |
],
|
| 546 |
},
|
| 547 |
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 548 |
},
|
| 549 |
-
[
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 550 |
);
|
| 551 |
|
| 552 |
const handleSendMessage = useCallback(
|
|
@@ -557,12 +576,11 @@ export const useSendMessage = () => {
|
|
| 557 |
const data = await setConversation(message);
|
| 558 |
if (data.retcode === 0) {
|
| 559 |
const id = data.data.id;
|
| 560 |
-
handleClickConversation(id);
|
| 561 |
sendMessage(message, id);
|
| 562 |
}
|
| 563 |
}
|
| 564 |
},
|
| 565 |
-
[conversationId,
|
| 566 |
);
|
| 567 |
|
| 568 |
return { sendMessage: handleSendMessage };
|
|
|
|
| 78 |
|
| 79 |
const setCurrentDialog = useCallback(
|
| 80 |
(dialogId: string) => {
|
| 81 |
+
dispatch({
|
| 82 |
+
type: 'chatModel/setCurrentDialog',
|
| 83 |
+
payload: { id: dialogId },
|
| 84 |
+
});
|
|
|
|
|
|
|
| 85 |
},
|
| 86 |
[dispatch],
|
| 87 |
);
|
|
|
|
| 425 |
content: message,
|
| 426 |
id: uuid(),
|
| 427 |
} as IMessage,
|
| 428 |
+
{
|
| 429 |
+
role: MessageType.Assistant,
|
| 430 |
+
content: '',
|
| 431 |
+
id: uuid(),
|
| 432 |
+
reference: [],
|
| 433 |
+
} as IMessage,
|
| 434 |
],
|
| 435 |
};
|
| 436 |
});
|
|
|
|
| 529 |
const conversation: IClientConversation = useSelector(
|
| 530 |
(state: any) => state.chatModel.currentConversation,
|
| 531 |
);
|
| 532 |
+
const fetchConversation = useFetchConversation();
|
| 533 |
|
| 534 |
const { handleClickConversation } = useClickConversationCard();
|
| 535 |
|
| 536 |
const sendMessage = useCallback(
|
| 537 |
+
async (message: string, id?: string) => {
|
| 538 |
+
const retcode = await dispatch<any>({
|
| 539 |
type: 'chatModel/completeConversation',
|
| 540 |
payload: {
|
| 541 |
conversation_id: id ?? conversationId,
|
|
|
|
| 550 |
],
|
| 551 |
},
|
| 552 |
});
|
| 553 |
+
|
| 554 |
+
if (retcode === 0) {
|
| 555 |
+
if (id) {
|
| 556 |
+
handleClickConversation(id);
|
| 557 |
+
} else {
|
| 558 |
+
fetchConversation(conversationId);
|
| 559 |
+
}
|
| 560 |
+
}
|
| 561 |
},
|
| 562 |
+
[
|
| 563 |
+
dispatch,
|
| 564 |
+
conversation?.message,
|
| 565 |
+
conversationId,
|
| 566 |
+
fetchConversation,
|
| 567 |
+
handleClickConversation,
|
| 568 |
+
],
|
| 569 |
);
|
| 570 |
|
| 571 |
const handleSendMessage = useCallback(
|
|
|
|
| 576 |
const data = await setConversation(message);
|
| 577 |
if (data.retcode === 0) {
|
| 578 |
const id = data.data.id;
|
|
|
|
| 579 |
sendMessage(message, id);
|
| 580 |
}
|
| 581 |
}
|
| 582 |
},
|
| 583 |
+
[conversationId, setConversation, sendMessage],
|
| 584 |
);
|
| 585 |
|
| 586 |
return { sendMessage: handleSendMessage };
|
web/src/pages/chat/index.less
CHANGED
|
@@ -38,6 +38,7 @@
|
|
| 38 |
|
| 39 |
.chatTitleContent {
|
| 40 |
padding: 5px 10px;
|
|
|
|
| 41 |
}
|
| 42 |
|
| 43 |
.chatTitleCard {
|
|
|
|
| 38 |
|
| 39 |
.chatTitleContent {
|
| 40 |
padding: 5px 10px;
|
| 41 |
+
overflow: auto;
|
| 42 |
}
|
| 43 |
|
| 44 |
.chatTitleCard {
|
web/src/pages/chat/index.tsx
CHANGED
|
@@ -76,9 +76,9 @@ const Chat = () => {
|
|
| 76 |
(info: any) => {
|
| 77 |
info?.domEvent?.preventDefault();
|
| 78 |
info?.domEvent?.stopPropagation();
|
| 79 |
-
if (dialogId) {
|
| 80 |
-
|
| 81 |
-
}
|
| 82 |
showModal();
|
| 83 |
};
|
| 84 |
|
|
|
|
| 76 |
(info: any) => {
|
| 77 |
info?.domEvent?.preventDefault();
|
| 78 |
info?.domEvent?.stopPropagation();
|
| 79 |
+
// if (dialogId) {
|
| 80 |
+
setCurrentDialog(dialogId ?? '');
|
| 81 |
+
// }
|
| 82 |
showModal();
|
| 83 |
};
|
| 84 |
|
web/src/pages/chat/model.ts
CHANGED
|
@@ -140,14 +140,15 @@ const model: DvaModel<ChatModelState> = {
|
|
| 140 |
},
|
| 141 |
*completeConversation({ payload }, { call, put }) {
|
| 142 |
const { data } = yield call(chatService.completeConversation, payload);
|
| 143 |
-
if (data.retcode === 0) {
|
| 144 |
-
|
| 145 |
-
|
| 146 |
-
|
| 147 |
-
|
| 148 |
-
|
| 149 |
-
|
| 150 |
-
}
|
|
|
|
| 151 |
},
|
| 152 |
*removeConversation({ payload }, { call, put }) {
|
| 153 |
const { data } = yield call(chatService.removeConversation, {
|
|
|
|
| 140 |
},
|
| 141 |
*completeConversation({ payload }, { call, put }) {
|
| 142 |
const { data } = yield call(chatService.completeConversation, payload);
|
| 143 |
+
// if (data.retcode === 0) {
|
| 144 |
+
// yield put({
|
| 145 |
+
// type: 'getConversation',
|
| 146 |
+
// payload: {
|
| 147 |
+
// conversation_id: payload.conversation_id,
|
| 148 |
+
// },
|
| 149 |
+
// });
|
| 150 |
+
// }
|
| 151 |
+
return data.retcode;
|
| 152 |
},
|
| 153 |
*removeConversation({ payload }, { call, put }) {
|
| 154 |
const { data } = yield call(chatService.removeConversation, {
|