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)
* 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
This commit is contained in:
parent
602038ac49
commit
8b2bbd79e4
@ -18,7 +18,7 @@ export default defineConfig({
|
|||||||
dva: {},
|
dva: {},
|
||||||
lessLoader: {
|
lessLoader: {
|
||||||
modifyVars: {
|
modifyVars: {
|
||||||
hack: `true; @import "~@/less/variable.less";`,
|
hack: `true; @import "~@/less/index.less";`,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
proxy: {
|
proxy: {
|
||||||
|
|||||||
@ -1,5 +1,4 @@
|
|||||||
import { ReactComponent as StarIon } from '@/assets/svg/chat-star.svg';
|
import { ReactComponent as StarIon } from '@/assets/svg/chat-star.svg';
|
||||||
import { ReactComponent as FileIcon } from '@/assets/svg/file-management.svg';
|
|
||||||
import { ReactComponent as KnowledgeBaseIcon } from '@/assets/svg/knowledge-base.svg';
|
import { ReactComponent as KnowledgeBaseIcon } from '@/assets/svg/knowledge-base.svg';
|
||||||
import { ReactComponent as Logo } from '@/assets/svg/logo.svg';
|
import { ReactComponent as Logo } from '@/assets/svg/logo.svg';
|
||||||
import { Layout, Radio, Space, theme } from 'antd';
|
import { Layout, Radio, Space, theme } from 'antd';
|
||||||
@ -23,7 +22,7 @@ const RagHeader = () => {
|
|||||||
() => [
|
() => [
|
||||||
{ path: '/knowledge', name: 'Knowledge Base', icon: KnowledgeBaseIcon },
|
{ path: '/knowledge', name: 'Knowledge Base', icon: KnowledgeBaseIcon },
|
||||||
{ path: '/chat', name: 'Chat', icon: StarIon },
|
{ path: '/chat', name: 'Chat', icon: StarIon },
|
||||||
{ path: '/file', name: 'File Management', icon: FileIcon },
|
// { path: '/file', name: 'File Management', icon: FileIcon },
|
||||||
],
|
],
|
||||||
[],
|
[],
|
||||||
);
|
);
|
||||||
|
|||||||
2
web/src/less/index.less
Normal file
2
web/src/less/index.less
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
@import './variable.less';
|
||||||
|
@import './mixins.less';
|
||||||
31
web/src/less/mixins.less
Normal file
31
web/src/less/mixins.less
Normal file
@ -0,0 +1,31 @@
|
|||||||
|
.chunkText() {
|
||||||
|
em {
|
||||||
|
color: red;
|
||||||
|
font-style: normal;
|
||||||
|
}
|
||||||
|
table {
|
||||||
|
width: 100%;
|
||||||
|
}
|
||||||
|
|
||||||
|
caption {
|
||||||
|
color: @blurBackground;
|
||||||
|
font-size: 20px;
|
||||||
|
height: 50px;
|
||||||
|
line-height: 50px;
|
||||||
|
font-weight: 600;
|
||||||
|
margin-bottom: 10px;
|
||||||
|
}
|
||||||
|
|
||||||
|
th {
|
||||||
|
color: #fff;
|
||||||
|
background-color: @blurBackground;
|
||||||
|
}
|
||||||
|
|
||||||
|
td:hover {
|
||||||
|
background: @blurBackgroundHover;
|
||||||
|
}
|
||||||
|
|
||||||
|
tr:nth-child(even) {
|
||||||
|
background-color: #f2f2f2;
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -9,35 +9,7 @@
|
|||||||
|
|
||||||
.content {
|
.content {
|
||||||
flex: 1;
|
flex: 1;
|
||||||
em {
|
.chunkText;
|
||||||
color: red;
|
|
||||||
font-style: normal;
|
|
||||||
}
|
|
||||||
table {
|
|
||||||
width: 100%;
|
|
||||||
}
|
|
||||||
|
|
||||||
caption {
|
|
||||||
color: @blurBackground;
|
|
||||||
font-size: 20px;
|
|
||||||
height: 50px;
|
|
||||||
line-height: 50px;
|
|
||||||
font-weight: 600;
|
|
||||||
margin-bottom: 10px;
|
|
||||||
}
|
|
||||||
|
|
||||||
th {
|
|
||||||
color: #fff;
|
|
||||||
background-color: @blurBackground;
|
|
||||||
}
|
|
||||||
|
|
||||||
td:hover {
|
|
||||||
background: @blurBackgroundHover;
|
|
||||||
}
|
|
||||||
|
|
||||||
tr:nth-child(even) {
|
|
||||||
background-color: #f2f2f2;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
.cardSelected {
|
.cardSelected {
|
||||||
|
|||||||
@ -121,6 +121,7 @@ const ChatConfigurationModal = ({ visible, hideModal, id }: IProps) => {
|
|||||||
);
|
);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
|
if (visible) {
|
||||||
const icon = currentDialog.icon;
|
const icon = currentDialog.icon;
|
||||||
let fileList: UploadFile[] = [];
|
let fileList: UploadFile[] = [];
|
||||||
|
|
||||||
@ -128,7 +129,8 @@ const ChatConfigurationModal = ({ visible, hideModal, id }: IProps) => {
|
|||||||
fileList = [{ uid: '1', name: 'file', thumbUrl: icon, status: 'done' }];
|
fileList = [{ uid: '1', name: 'file', thumbUrl: icon, status: 'done' }];
|
||||||
}
|
}
|
||||||
form.setFieldsValue({ ...currentDialog, icon: fileList });
|
form.setFieldsValue({ ...currentDialog, icon: fileList });
|
||||||
}, [currentDialog, form]);
|
}
|
||||||
|
}, [currentDialog, form, visible]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Modal
|
<Modal
|
||||||
|
|||||||
@ -28,6 +28,9 @@
|
|||||||
padding: 0 14px;
|
padding: 0 14px;
|
||||||
background-color: rgba(249, 250, 251, 1);
|
background-color: rgba(249, 250, 251, 1);
|
||||||
}
|
}
|
||||||
|
.messageEmpty {
|
||||||
|
width: 300px;
|
||||||
|
}
|
||||||
.referenceIcon {
|
.referenceIcon {
|
||||||
padding: 0 6px;
|
padding: 0 6px;
|
||||||
}
|
}
|
||||||
@ -52,3 +55,6 @@
|
|||||||
.referenceImagePreview {
|
.referenceImagePreview {
|
||||||
width: 600px;
|
width: 600px;
|
||||||
}
|
}
|
||||||
|
.chunkContentText {
|
||||||
|
.chunkText;
|
||||||
|
}
|
||||||
|
|||||||
@ -11,6 +11,7 @@ import {
|
|||||||
Input,
|
Input,
|
||||||
List,
|
List,
|
||||||
Popover,
|
Popover,
|
||||||
|
Skeleton,
|
||||||
Space,
|
Space,
|
||||||
} from 'antd';
|
} from 'antd';
|
||||||
import classNames from 'classnames';
|
import classNames from 'classnames';
|
||||||
@ -100,7 +101,12 @@ const MessageItem = ({
|
|||||||
></Image>
|
></Image>
|
||||||
</Popover>
|
</Popover>
|
||||||
<Space direction={'vertical'}>
|
<Space direction={'vertical'}>
|
||||||
<div>{chunkItem?.content_with_weight}</div>
|
<div
|
||||||
|
dangerouslySetInnerHTML={{
|
||||||
|
__html: chunkItem?.content_with_weight,
|
||||||
|
}}
|
||||||
|
className={styles.chunkContentText}
|
||||||
|
></div>
|
||||||
{documentId && (
|
{documentId && (
|
||||||
<Flex gap={'middle'}>
|
<Flex gap={'middle'}>
|
||||||
<img src={fileThumbnails[documentId]} alt="" />
|
<img src={fileThumbnails[documentId]} alt="" />
|
||||||
@ -171,17 +177,24 @@ const MessageItem = ({
|
|||||||
<Flex vertical gap={8} flex={1}>
|
<Flex vertical gap={8} flex={1}>
|
||||||
<b>{isAssistant ? '' : userInfo.nickname}</b>
|
<b>{isAssistant ? '' : userInfo.nickname}</b>
|
||||||
<div className={styles.messageText}>
|
<div className={styles.messageText}>
|
||||||
|
{item.content ? (
|
||||||
<Markdown
|
<Markdown
|
||||||
rehypePlugins={[rehypeWrapReference]}
|
rehypePlugins={[rehypeWrapReference]}
|
||||||
components={
|
components={
|
||||||
{
|
{
|
||||||
'custom-typography': ({ children }: { children: string }) =>
|
'custom-typography': ({
|
||||||
renderReference(children),
|
children,
|
||||||
|
}: {
|
||||||
|
children: string;
|
||||||
|
}) => renderReference(children),
|
||||||
} as any
|
} as any
|
||||||
}
|
}
|
||||||
>
|
>
|
||||||
{item.content}
|
{item.content}
|
||||||
</Markdown>
|
</Markdown>
|
||||||
|
) : (
|
||||||
|
<Skeleton active className={styles.messageEmpty} />
|
||||||
|
)}
|
||||||
</div>
|
</div>
|
||||||
{isAssistant && referenceDocumentList.length > 0 && (
|
{isAssistant && referenceDocumentList.length > 0 && (
|
||||||
<List
|
<List
|
||||||
|
|||||||
@ -78,12 +78,10 @@ export const useSetCurrentDialog = () => {
|
|||||||
|
|
||||||
const setCurrentDialog = useCallback(
|
const setCurrentDialog = useCallback(
|
||||||
(dialogId: string) => {
|
(dialogId: string) => {
|
||||||
if (dialogId) {
|
|
||||||
dispatch({
|
dispatch({
|
||||||
type: 'chatModel/setCurrentDialog',
|
type: 'chatModel/setCurrentDialog',
|
||||||
payload: { id: dialogId },
|
payload: { id: dialogId },
|
||||||
});
|
});
|
||||||
}
|
|
||||||
},
|
},
|
||||||
[dispatch],
|
[dispatch],
|
||||||
);
|
);
|
||||||
@ -427,6 +425,12 @@ export const useSelectCurrentConversation = () => {
|
|||||||
content: message,
|
content: message,
|
||||||
id: uuid(),
|
id: uuid(),
|
||||||
} as IMessage,
|
} as IMessage,
|
||||||
|
{
|
||||||
|
role: MessageType.Assistant,
|
||||||
|
content: '',
|
||||||
|
id: uuid(),
|
||||||
|
reference: [],
|
||||||
|
} as IMessage,
|
||||||
],
|
],
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
@ -525,12 +529,13 @@ export const useSendMessage = () => {
|
|||||||
const conversation: IClientConversation = useSelector(
|
const conversation: IClientConversation = useSelector(
|
||||||
(state: any) => state.chatModel.currentConversation,
|
(state: any) => state.chatModel.currentConversation,
|
||||||
);
|
);
|
||||||
|
const fetchConversation = useFetchConversation();
|
||||||
|
|
||||||
const { handleClickConversation } = useClickConversationCard();
|
const { handleClickConversation } = useClickConversationCard();
|
||||||
|
|
||||||
const sendMessage = useCallback(
|
const sendMessage = useCallback(
|
||||||
(message: string, id?: string) => {
|
async (message: string, id?: string) => {
|
||||||
dispatch({
|
const retcode = await dispatch<any>({
|
||||||
type: 'chatModel/completeConversation',
|
type: 'chatModel/completeConversation',
|
||||||
payload: {
|
payload: {
|
||||||
conversation_id: id ?? conversationId,
|
conversation_id: id ?? conversationId,
|
||||||
@ -545,8 +550,22 @@ export const useSendMessage = () => {
|
|||||||
],
|
],
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
|
if (retcode === 0) {
|
||||||
|
if (id) {
|
||||||
|
handleClickConversation(id);
|
||||||
|
} else {
|
||||||
|
fetchConversation(conversationId);
|
||||||
|
}
|
||||||
|
}
|
||||||
},
|
},
|
||||||
[dispatch, conversation?.message, conversationId],
|
[
|
||||||
|
dispatch,
|
||||||
|
conversation?.message,
|
||||||
|
conversationId,
|
||||||
|
fetchConversation,
|
||||||
|
handleClickConversation,
|
||||||
|
],
|
||||||
);
|
);
|
||||||
|
|
||||||
const handleSendMessage = useCallback(
|
const handleSendMessage = useCallback(
|
||||||
@ -557,12 +576,11 @@ export const useSendMessage = () => {
|
|||||||
const data = await setConversation(message);
|
const data = await setConversation(message);
|
||||||
if (data.retcode === 0) {
|
if (data.retcode === 0) {
|
||||||
const id = data.data.id;
|
const id = data.data.id;
|
||||||
handleClickConversation(id);
|
|
||||||
sendMessage(message, id);
|
sendMessage(message, id);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
[conversationId, handleClickConversation, setConversation, sendMessage],
|
[conversationId, setConversation, sendMessage],
|
||||||
);
|
);
|
||||||
|
|
||||||
return { sendMessage: handleSendMessage };
|
return { sendMessage: handleSendMessage };
|
||||||
|
|||||||
@ -38,6 +38,7 @@
|
|||||||
|
|
||||||
.chatTitleContent {
|
.chatTitleContent {
|
||||||
padding: 5px 10px;
|
padding: 5px 10px;
|
||||||
|
overflow: auto;
|
||||||
}
|
}
|
||||||
|
|
||||||
.chatTitleCard {
|
.chatTitleCard {
|
||||||
|
|||||||
@ -76,9 +76,9 @@ const Chat = () => {
|
|||||||
(info: any) => {
|
(info: any) => {
|
||||||
info?.domEvent?.preventDefault();
|
info?.domEvent?.preventDefault();
|
||||||
info?.domEvent?.stopPropagation();
|
info?.domEvent?.stopPropagation();
|
||||||
if (dialogId) {
|
// if (dialogId) {
|
||||||
setCurrentDialog(dialogId);
|
setCurrentDialog(dialogId ?? '');
|
||||||
}
|
// }
|
||||||
showModal();
|
showModal();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@ -140,14 +140,15 @@ const model: DvaModel<ChatModelState> = {
|
|||||||
},
|
},
|
||||||
*completeConversation({ payload }, { call, put }) {
|
*completeConversation({ payload }, { call, put }) {
|
||||||
const { data } = yield call(chatService.completeConversation, payload);
|
const { data } = yield call(chatService.completeConversation, payload);
|
||||||
if (data.retcode === 0) {
|
// if (data.retcode === 0) {
|
||||||
yield put({
|
// yield put({
|
||||||
type: 'getConversation',
|
// type: 'getConversation',
|
||||||
payload: {
|
// payload: {
|
||||||
conversation_id: payload.conversation_id,
|
// conversation_id: payload.conversation_id,
|
||||||
},
|
// },
|
||||||
});
|
// });
|
||||||
}
|
// }
|
||||||
|
return data.retcode;
|
||||||
},
|
},
|
||||||
*removeConversation({ payload }, { call, put }) {
|
*removeConversation({ payload }, { call, put }) {
|
||||||
const { data } = yield call(chatService.removeConversation, {
|
const { data } = yield call(chatService.removeConversation, {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user