diff --git a/web/package.json b/web/package.json index ff51bb01..e1c430ed 100644 --- a/web/package.json +++ b/web/package.json @@ -2,7 +2,7 @@ "private": true, "author": "zhaofengchao <13723060510@163.com>", "scripts": { - "dev": "set PORT=9000&&umi dev", + "dev": "cross-env PORT=9000 umi dev", "build": "umi build", "postinstall": "umi setup", "setup": "umi setup", @@ -30,6 +30,7 @@ "@types/react": "^18.0.33", "@types/react-dom": "^18.0.11", "@umijs/plugins": "^4.1.0", + "cross-env": "^7.0.3", "typescript": "^5.0.3", "umi-plugin-icons": "^0.1.1" } diff --git a/web/src/pages/add-knowledge/components/knowledge-chunk/createModal.tsx b/web/src/pages/add-knowledge/components/knowledge-chunk/components/createModal.tsx similarity index 91% rename from web/src/pages/add-knowledge/components/knowledge-chunk/createModal.tsx rename to web/src/pages/add-knowledge/components/knowledge-chunk/components/createModal.tsx index 8414bfc4..8e9e8c37 100644 --- a/web/src/pages/add-knowledge/components/knowledge-chunk/createModal.tsx +++ b/web/src/pages/add-knowledge/components/knowledge-chunk/components/createModal.tsx @@ -14,10 +14,12 @@ interface kFProps { dispatch: Dispatch; chunkModel: chunkModelState; getChunkList: () => void; - doc_id: string + isShowCreateModal: boolean; + doc_id: string; + chunk_id: string } -const Index: React.FC = ({ chunkModel, dispatch, getChunkList, doc_id }) => { - const { isShowCreateModal, chunk_id, chunkInfo } = chunkModel +const Index: React.FC = ({ dispatch, getChunkList, doc_id, isShowCreateModal, chunk_id }) => { + // const { , chunkInfo } = chunkModel const [important_kwd, setImportantKwd] = useState(['Unremovable', 'Tag 2', 'Tag 3']); const { t } = useTranslation() const handleCancel = () => { @@ -29,6 +31,7 @@ const Index: React.FC = ({ chunkModel, dispatch, getChunkList, doc_id } }); }; useEffect(() => { + console.log(chunk_id, isShowCreateModal) if (chunk_id && isShowCreateModal) { dispatch({ type: 'chunkModel/get_chunk', @@ -85,7 +88,7 @@ const Index: React.FC = ({ chunkModel, dispatch, getChunkList, doc_id } label="chunk 内容" name="content_ltks" - rules={[{ required: true, message: 'Please input name!' }]} + rules={[{ required: true, message: 'Please input value!' }]} > diff --git a/web/src/pages/add-knowledge/components/knowledge-chunk/editTag.tsx b/web/src/pages/add-knowledge/components/knowledge-chunk/components/editTag.tsx similarity index 100% rename from web/src/pages/add-knowledge/components/knowledge-chunk/editTag.tsx rename to web/src/pages/add-knowledge/components/knowledge-chunk/components/editTag.tsx diff --git a/web/src/pages/add-knowledge/components/knowledge-chunk/index.tsx b/web/src/pages/add-knowledge/components/knowledge-chunk/index.tsx index 07682091..6f80e7f1 100644 --- a/web/src/pages/add-knowledge/components/knowledge-chunk/index.tsx +++ b/web/src/pages/add-knowledge/components/knowledge-chunk/index.tsx @@ -4,7 +4,7 @@ import { Card, Row, Col, Input, Select, Switch, Pagination, Spin, Button, Popcon import { MinusSquareOutlined, DeleteOutlined, } from '@ant-design/icons'; import type { PaginationProps } from 'antd'; import { api_host } from '@/utils/api' -import CreateModal from './createModal' +import CreateModal from './components/createModal' import styles from './index.less' @@ -21,7 +21,7 @@ const Index: React.FC = ({ chunkModel, dispatch, doc_id }) => { const navigate = useNavigate() const [pagination, setPagination] = useState({ page: 1, size: 30 }) // const [datas, setDatas] = useState(data) - const { data = [], total, loading } = chunkModel + const { data = [], total, loading, chunk_id, isShowCreateModal } = chunkModel console.log(chunkModel) const getChunkList = (value?: string) => { dispatch({ @@ -66,7 +66,8 @@ const Index: React.FC = ({ chunkModel, dispatch, doc_id }) => { type: 'chunkModel/updateState', payload: { isShowCreateModal: true, - chunk_id + chunk_id, + doc_id }, callback: getChunkList }); @@ -216,7 +217,7 @@ const Index: React.FC = ({ chunkModel, dispatch, doc_id }) => { - + ) }; diff --git a/web/src/pages/add-knowledge/components/knowledge-chunk/model.ts b/web/src/pages/add-knowledge/components/knowledge-chunk/model.ts index b81b1692..9091c70d 100644 --- a/web/src/pages/add-knowledge/components/knowledge-chunk/model.ts +++ b/web/src/pages/add-knowledge/components/knowledge-chunk/model.ts @@ -8,6 +8,7 @@ export interface chunkModelState { total: number; isShowCreateModal: boolean; chunk_id: string; + doc_id: string; chunkInfo: any } export interface chunkgModelType { @@ -33,6 +34,7 @@ const Model: chunkgModelType = { total: 0, isShowCreateModal: false, chunk_id: '', + doc_id: '', chunkInfo: {} }, subscriptions: { diff --git a/web/src/pages/add-knowledge/components/knowledge-file/createEFileModal.tsx b/web/src/pages/add-knowledge/components/knowledge-file/createEFileModal.tsx index a43674bf..fc9fcf92 100644 --- a/web/src/pages/add-knowledge/components/knowledge-file/createEFileModal.tsx +++ b/web/src/pages/add-knowledge/components/knowledge-file/createEFileModal.tsx @@ -65,7 +65,7 @@ const Index: React.FC = ({ kFModel, dispatch, getKfList, kb_id }) => { label="文件名" name="name" - rules={[{ required: true, message: 'Please input name!' }]} + rules={[{ required: true, message: 'Please input value!' }]} > diff --git a/web/src/pages/add-knowledge/components/knowledge-search/index.less b/web/src/pages/add-knowledge/components/knowledge-search/index.less new file mode 100644 index 00000000..4f51079a --- /dev/null +++ b/web/src/pages/add-knowledge/components/knowledge-search/index.less @@ -0,0 +1,79 @@ +.chunkPage { + padding: 24px; + display: flex; + height: calc(100vh - 112px); + // flex-direction: column; + + .filter { + margin-right: 20px; + display: flex; + height: 32px; + width: 300px; + flex-wrap: wrap; + justify-content: space-between; + } + + .pageContainer { + flex: 1; + display: flex; + flex-direction: column; + + .pageContent { + flex: 1; + width: 100%; + padding-right: 12px; + overflow-y: auto; + + .spin { + min-height: 400px; + } + } + + .pageFooter { + height: 32px; + float: right; + } + } + +} + +.container { + height: 100px; + display: flex; + flex-direction: column; + justify-content: space-between; + + .content { + display: flex; + justify-content: space-between; + + .context { + flex: 1; + // width: 207px; + height: 88px; + overflow: hidden; + } + } + + .footer { + height: 20px; + + .text { + margin-left: 10px; + } + } +} + +.card { + :global { + .ant-card-body { + padding: 10px; + margin: 0; + } + + margin-bottom: 10px; + } + + cursor: pointer; + +} \ No newline at end of file diff --git a/web/src/pages/add-knowledge/components/knowledge-search/index.tsx b/web/src/pages/add-knowledge/components/knowledge-search/index.tsx index 619f2ff8..a50fb0c3 100644 --- a/web/src/pages/add-knowledge/components/knowledge-search/index.tsx +++ b/web/src/pages/add-knowledge/components/knowledge-search/index.tsx @@ -1,3 +1,247 @@ -export default () => { - return
知识库搜索
-} \ No newline at end of file +import React, { useEffect, useState, useCallback, } from 'react'; +import { useNavigate, connect, Dispatch } from 'umi' +import { Card, Row, Col, Input, Select, Switch, Pagination, Spin, Button, Popconfirm } from 'antd'; +import { MinusSquareOutlined, DeleteOutlined, } from '@ant-design/icons'; +import type { PaginationProps } from 'antd'; +import { api_host } from '@/utils/api' +import CreateModal from '../knowledge-chunk/components/createModal' + + +import styles from './index.less' +import { debounce } from 'lodash'; +import type { kSearchModelState } from './model' +import type { chunkModelState } from '../knowledge-chunk/model' +interface chunkProps { + dispatch: Dispatch; + kSearchModel: kSearchModelState; + chunkModel: chunkModelState; + kb_id: string +} +const Index: React.FC = ({ kSearchModel, chunkModel, dispatch, kb_id }) => { + + const { data = [], total, loading, d_list = [], question, doc_ids, pagination, } = kSearchModel + const { chunk_id, doc_id, isShowCreateModal } = chunkModel + const getChunkList = () => { + dispatch({ + type: 'kSearchModel/updateState', + payload: { + loading: true + } + }); + interface payloadType { + kb_id: string; + question?: string; + doc_ids: any[]; + similarity_threshold?: number + } + const payload: payloadType = { + kb_id, + question, + doc_ids, + similarity_threshold: 0.1 + } + dispatch({ + type: 'kSearchModel/chunk_list', + payload: { + ...payload, + ...pagination + } + }); + } + const confirm = (id: string) => { + console.log(id) + dispatch({ + type: 'kSearchModel/rm_chunk', + payload: { + chunk_ids: [id] + }, + callback: getChunkList + }); + }; + const handleEditchunk = (item: any) => { + const { chunk_id, doc_id } = item + dispatch({ + type: 'chunkModel/updateState', + payload: { + isShowCreateModal: true, + chunk_id, + doc_id + }, + callback: getChunkList + }); + } + const onShowSizeChange: PaginationProps['onShowSizeChange'] = (page, size) => { + dispatch({ + type: 'kSearchModel/updateState', + payload: { + pagination: { page, size } + } + }); + }; + useEffect(() => { + dispatch({ + type: 'kSearchModel/updateState', + payload: { + loading: false, + doc_ids: [], + question: "" + } + }); + dispatch({ + type: 'kSearchModel/getKfList', + payload: { + kb_id + } + + }); + }, []) + const switchChunk = (item: any, available_int: boolean) => { + const { chunk_id, doc_id } = item + dispatch({ + type: 'kSearchModel/updateState', + payload: { + loading: true + } + }); + dispatch({ + type: 'kSearchModel/switch_chunk', + payload: { + chunk_ids: [chunk_id], + doc_id, + available_int + }, + callback: getChunkList + }); + } + + + useEffect(() => { + getChunkList() + }, [doc_ids, pagination, question]) + const debounceChange = debounce((value) => { + dispatch({ + type: 'kSearchModel/updateState', + payload: { + question: value + } + }); + }, 300) + const debounceCallback = useCallback((value: string) => debounceChange(value), []) + const handleInputChange = (e: React.ChangeEvent) => { + const value = e.target.value + debounceCallback(value) + } + const handleSelectChange = (value: + any[]) => { + dispatch({ + type: 'kSearchModel/updateState', + payload: { + doc_ids: value + } + }); + } + console.log('loading', loading) + return (<> +
+
+ + { title === 'register' && = ({ {...formItemLayout} name="password" label="Password" - rules={[{ required: true, message: 'Please input your name' }]} + rules={[{ required: true, message: 'Please input value' }]} > - + { title === 'login' && = ({ settingModel, dispatch }) => { label="旧密码" name="password" - rules={[{ required: true, message: 'Please input your password!' }]} + rules={[{ required: true, message: 'Please input value' }]} > diff --git a/web/src/pages/setting/SSModal.tsx b/web/src/pages/setting/SSModal.tsx index c6b2f34c..09793374 100644 --- a/web/src/pages/setting/SSModal.tsx +++ b/web/src/pages/setting/SSModal.tsx @@ -76,7 +76,7 @@ const Index: FC = ({ settingModel, dispatch }) => { label="embedding 模型" name="embd_id" - rules={[{ required: true, message: 'Please input your password!' }]} + rules={[{ required: true, message: 'Please input value' }]} initialValue={tenantIfo.embd_id} > @@ -93,7 +93,7 @@ const Index: FC = ({ settingModel, dispatch }) => { label="chat 模型" name="llm_id" - rules={[{ required: true, message: 'Please input your password!' }]} + rules={[{ required: true, message: 'Please input value' }]} initialValue={tenantIfo.llm_id} > @@ -110,7 +110,7 @@ const Index: FC = ({ settingModel, dispatch }) => { label="image2text 模型" name="img2txt_id" - rules={[{ required: true, message: 'Please input your password!' }]} + rules={[{ required: true, message: 'Please input value' }]} initialValue={tenantIfo.img2txt_id} > @@ -127,7 +127,7 @@ const Index: FC = ({ settingModel, dispatch }) => { label="speech2text 模型" name="asr_id" - rules={[{ required: true, message: 'Please input your password!' }]} + rules={[{ required: true, message: 'Please input value' }]} initialValue={tenantIfo.asr_id} > diff --git a/web/src/services/kbService.ts b/web/src/services/kbService.ts index 688fce21..2ea49179 100644 --- a/web/src/services/kbService.ts +++ b/web/src/services/kbService.ts @@ -16,7 +16,10 @@ const { chunk_list, create_chunk, set_chunk, - get_chunk, switch_chunk, rm_chunk } = api; + get_chunk, + switch_chunk, + rm_chunk, + retrieval_test } = api; interface kbService { createKb: () => void; updateKb: () => void; @@ -34,6 +37,7 @@ interface kbService { get_chunk: () => void; switch_chunk: () => void; rm_chunk: () => void; + retrieval_test: () => void; } const kbService: kbService = registerServer( { @@ -104,7 +108,10 @@ const kbService: kbService = registerServer( url: rm_chunk, method: 'post' }, - + retrieval_test: { + url: retrieval_test, + method: 'post' + }, }, request ); diff --git a/web/src/utils/api.ts b/web/src/utils/api.ts index a88c857e..6e297676 100644 --- a/web/src/utils/api.ts +++ b/web/src/utils/api.ts @@ -39,6 +39,8 @@ export default { get_chunk: `${api_host}/chunk/get`, switch_chunk: `${api_host}/chunk/switch`, rm_chunk: `${api_host}/chunk/rm`, + retrieval_test: `${api_host}/chunk/retrieval_test`, +