diff --git a/web/.umirc.ts b/web/.umirc.ts index 84afb1a4..4ecbc3c5 100644 --- a/web/.umirc.ts +++ b/web/.umirc.ts @@ -18,7 +18,7 @@ export default defineConfig({ dva: {}, lessLoader: { modifyVars: { - hack: `true; @import "~@/less/variable.less";`, + hack: `true; @import "~@/less/index.less";`, }, }, proxy: { diff --git a/web/src/layouts/components/header/index.tsx b/web/src/layouts/components/header/index.tsx index 7705cae7..210c823b 100644 --- a/web/src/layouts/components/header/index.tsx +++ b/web/src/layouts/components/header/index.tsx @@ -1,5 +1,4 @@ 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 Logo } from '@/assets/svg/logo.svg'; import { Layout, Radio, Space, theme } from 'antd'; @@ -23,7 +22,7 @@ const RagHeader = () => { () => [ { path: '/knowledge', name: 'Knowledge Base', icon: KnowledgeBaseIcon }, { path: '/chat', name: 'Chat', icon: StarIon }, - { path: '/file', name: 'File Management', icon: FileIcon }, + // { path: '/file', name: 'File Management', icon: FileIcon }, ], [], ); diff --git a/web/src/less/index.less b/web/src/less/index.less new file mode 100644 index 00000000..25282993 --- /dev/null +++ b/web/src/less/index.less @@ -0,0 +1,2 @@ +@import './variable.less'; +@import './mixins.less'; diff --git a/web/src/less/mixins.less b/web/src/less/mixins.less new file mode 100644 index 00000000..734924b2 --- /dev/null +++ b/web/src/less/mixins.less @@ -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; + } +} diff --git a/web/src/pages/add-knowledge/components/knowledge-chunk/components/chunk-card/index.less b/web/src/pages/add-knowledge/components/knowledge-chunk/components/chunk-card/index.less index 8e6e4039..1ee2e3f5 100644 --- a/web/src/pages/add-knowledge/components/knowledge-chunk/components/chunk-card/index.less +++ b/web/src/pages/add-knowledge/components/knowledge-chunk/components/chunk-card/index.less @@ -9,35 +9,7 @@ .content { flex: 1; - 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; - } + .chunkText; } .cardSelected { diff --git a/web/src/pages/chat/chat-configuration-modal/index.tsx b/web/src/pages/chat/chat-configuration-modal/index.tsx index fcc38e22..aec87560 100644 --- a/web/src/pages/chat/chat-configuration-modal/index.tsx +++ b/web/src/pages/chat/chat-configuration-modal/index.tsx @@ -121,14 +121,16 @@ const ChatConfigurationModal = ({ visible, hideModal, id }: IProps) => { ); useEffect(() => { - const icon = currentDialog.icon; - let fileList: UploadFile[] = []; + if (visible) { + const icon = currentDialog.icon; + let fileList: UploadFile[] = []; - if (icon) { - fileList = [{ uid: '1', name: 'file', thumbUrl: icon, status: 'done' }]; + if (icon) { + 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 ( -
{chunkItem?.content_with_weight}
+
{documentId && ( @@ -171,17 +177,24 @@ const MessageItem = ({ {isAssistant ? '' : userInfo.nickname}
- - renderReference(children), - } as any - } - > - {item.content} - + {item.content ? ( + renderReference(children), + } as any + } + > + {item.content} + + ) : ( + + )}
{isAssistant && referenceDocumentList.length > 0 && ( { const setCurrentDialog = useCallback( (dialogId: string) => { - if (dialogId) { - dispatch({ - type: 'chatModel/setCurrentDialog', - payload: { id: dialogId }, - }); - } + dispatch({ + type: 'chatModel/setCurrentDialog', + payload: { id: dialogId }, + }); }, [dispatch], ); @@ -427,6 +425,12 @@ export const useSelectCurrentConversation = () => { content: message, id: uuid(), } as IMessage, + { + role: MessageType.Assistant, + content: '', + id: uuid(), + reference: [], + } as IMessage, ], }; }); @@ -525,12 +529,13 @@ export const useSendMessage = () => { const conversation: IClientConversation = useSelector( (state: any) => state.chatModel.currentConversation, ); + const fetchConversation = useFetchConversation(); const { handleClickConversation } = useClickConversationCard(); const sendMessage = useCallback( - (message: string, id?: string) => { - dispatch({ + async (message: string, id?: string) => { + const retcode = await dispatch({ type: 'chatModel/completeConversation', payload: { 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( @@ -557,12 +576,11 @@ export const useSendMessage = () => { const data = await setConversation(message); if (data.retcode === 0) { const id = data.data.id; - handleClickConversation(id); sendMessage(message, id); } } }, - [conversationId, handleClickConversation, setConversation, sendMessage], + [conversationId, setConversation, sendMessage], ); return { sendMessage: handleSendMessage }; diff --git a/web/src/pages/chat/index.less b/web/src/pages/chat/index.less index cb1546f2..57eb15a7 100644 --- a/web/src/pages/chat/index.less +++ b/web/src/pages/chat/index.less @@ -38,6 +38,7 @@ .chatTitleContent { padding: 5px 10px; + overflow: auto; } .chatTitleCard { diff --git a/web/src/pages/chat/index.tsx b/web/src/pages/chat/index.tsx index 59dcbe66..961ce1a7 100644 --- a/web/src/pages/chat/index.tsx +++ b/web/src/pages/chat/index.tsx @@ -76,9 +76,9 @@ const Chat = () => { (info: any) => { info?.domEvent?.preventDefault(); info?.domEvent?.stopPropagation(); - if (dialogId) { - setCurrentDialog(dialogId); - } + // if (dialogId) { + setCurrentDialog(dialogId ?? ''); + // } showModal(); }; diff --git a/web/src/pages/chat/model.ts b/web/src/pages/chat/model.ts index e885e60d..b3d632ba 100644 --- a/web/src/pages/chat/model.ts +++ b/web/src/pages/chat/model.ts @@ -140,14 +140,15 @@ const model: DvaModel = { }, *completeConversation({ payload }, { call, put }) { const { data } = yield call(chatService.completeConversation, payload); - if (data.retcode === 0) { - yield put({ - type: 'getConversation', - payload: { - conversation_id: payload.conversation_id, - }, - }); - } + // if (data.retcode === 0) { + // yield put({ + // type: 'getConversation', + // payload: { + // conversation_id: payload.conversation_id, + // }, + // }); + // } + return data.retcode; }, *removeConversation({ payload }, { call, put }) { const { data } = yield call(chatService.removeConversation, {