+
@@ -42,27 +54,46 @@ const PopoverContent = ({ record }: IProps) => {
};
export const ParsingStatusCell = ({ record }: IProps) => {
+ const dispatch = useDispatch();
const text = record.run;
const runningStatus = RunningStatusMap[text];
const isRunning = text === RunningStatus.RUNNING;
+ const OperationIcon = iconMap[text];
+
+ const handleOperationIconClick = () => {
+ dispatch({
+ type: 'kFModel/document_run',
+ payload: {
+ doc_ids: [record.id],
+ run: isRunning ? 2 : 1,
+ knowledgeBaseId: record.kb_id,
+ },
+ });
+ };
+
return (
-
}
- >
-
- {isRunning ? (
-
-
- {runningStatus.label}
- {record.progress * 100}%
-
- ) : (
- runningStatus.label
- )}
-
-
+
+ }
+ >
+
+ {isRunning ? (
+
+
+ {runningStatus.label}
+ {(record.progress * 100).toFixed(2)}%
+
+ ) : (
+ runningStatus.label
+ )}
+
+
+
+
+
+
);
};
diff --git a/web/src/pages/add-knowledge/components/knowledge-search/index.less b/web/src/pages/add-knowledge/components/knowledge-search/index.less
deleted file mode 100644
index 4f51079ac..000000000
--- a/web/src/pages/add-knowledge/components/knowledge-search/index.less
+++ /dev/null
@@ -1,79 +0,0 @@
-.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
deleted file mode 100644
index 6c17135ce..000000000
--- a/web/src/pages/add-knowledge/components/knowledge-search/index.tsx
+++ /dev/null
@@ -1,276 +0,0 @@
-import { useKnowledgeBaseId } from '@/hooks/knowledgeHook';
-import { useOneNamespaceEffectsLoading } from '@/hooks/storeHooks';
-import { api_host } from '@/utils/api';
-import { DeleteOutlined, MinusSquareOutlined } from '@ant-design/icons';
-import type { PaginationProps } from 'antd';
-import {
- Card,
- Col,
- Input,
- Pagination,
- Popconfirm,
- Row,
- Select,
- Spin,
- Switch,
-} from 'antd';
-import { debounce } from 'lodash';
-import React, { useCallback, useEffect } from 'react';
-import { useDispatch, useSelector } from 'umi';
-import CreateModal from '../knowledge-chunk/components/chunk-creating-modal';
-
-import styles from './index.less';
-
-const KnowledgeSearching = () => {
- const dispatch = useDispatch();
- const kSearchModel = useSelector((state: any) => state.kSearchModel);
- const chunkModel = useSelector((state: any) => state.chunkModel);
- const loading = useOneNamespaceEffectsLoading('kSearchModel', [
- 'chunk_list',
- 'switch_chunk',
- ]);
- const knowledgeBaseId = useKnowledgeBaseId();
-
- const {
- data = [],
- total,
- d_list = [],
- question,
- doc_ids,
- pagination,
- } = kSearchModel;
- const { chunk_id, doc_id, isShowCreateModal } = chunkModel;
-
- const getChunkList = () => {
- dispatch({
- type: 'kSearchModel/chunk_list',
- payload: {
- kb_id: knowledgeBaseId,
- },
- });
- };
- const confirm = (id: string) => {
- dispatch({
- type: 'kSearchModel/rm_chunk',
- payload: {
- chunk_ids: [id],
- kb_id: knowledgeBaseId,
- },
- });
- };
- const handleEditchunk = (item: any) => {
- const { chunk_id, doc_id } = item;
- dispatch({
- type: 'chunkModel/updateState',
- payload: {
- isShowCreateModal: true,
- chunk_id,
- doc_id,
- },
- });
- getChunkList();
- };
- const onShowSizeChange: PaginationProps['onShowSizeChange'] = (
- page,
- size,
- ) => {
- dispatch({
- type: 'kSearchModel/updateState',
- payload: {
- pagination: { page, size },
- },
- });
- };
- useEffect(() => {
- dispatch({
- type: 'kSearchModel/updateState',
- payload: {
- doc_ids: [],
- question: '',
- },
- });
- dispatch({
- type: 'kSearchModel/getKfList',
- payload: {
- kb_id: knowledgeBaseId,
- },
- });
- }, []);
- const switchChunk = (item: any, available_int: boolean) => {
- const { chunk_id, doc_id } = item;
-
- dispatch({
- type: 'kSearchModel/switch_chunk',
- payload: {
- chunk_ids: [chunk_id],
- doc_id,
- available_int,
- kb_id: knowledgeBaseId,
- },
- });
- };
-
- 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,
- },
- });
- };
-
- return (
- <>
-
-
-
-
-
-
-
-
-
-
- {data.map((item: any) => {
- return (
-
- {
- handleEditchunk(item);
- }}
- >
-
-
-
-
- {item.content_ltks}
-
-
- {
- e.stopPropagation();
- e.nativeEvent.stopImmediatePropagation();
- switchChunk(item, checked);
- }}
- />
-
-
-
-
-
- {item.doc_num}文档
-
-
-
- {item.chunk_num}个
-
-
-
- {item.token_num}千字符
-
-
- {
- e.stopPropagation();
- e.nativeEvent.stopImmediatePropagation();
- console.log(confirm);
- confirm(item.chunk_id);
- }}
- okText="Yes"
- cancelText="No"
- >
- {
- e.stopPropagation();
- e.nativeEvent.stopImmediatePropagation();
- }}
- />
-
-
-
-
-
-
- );
- })}
-
-
-
-
-
-
-
- >
- );
-};
-
-export default KnowledgeSearching;
diff --git a/web/src/pages/add-knowledge/components/knowledge-search/model.ts b/web/src/pages/add-knowledge/components/knowledge-search/model.ts
deleted file mode 100644
index 592417223..000000000
--- a/web/src/pages/add-knowledge/components/knowledge-search/model.ts
+++ /dev/null
@@ -1,160 +0,0 @@
-import kbService from '@/services/kbService';
-import omit from 'lodash/omit';
-import { DvaModel } from 'umi';
-
-export interface KSearchModelState {
- loading: boolean;
- data: any[];
- total: number;
- isShowCreateModal: boolean;
- chunk_id: string;
- chunkInfo: any;
- d_list: any[];
- question: string;
- doc_ids: any[];
- pagination: any;
- doc_id: string;
-}
-
-const model: DvaModel = {
- namespace: 'kSearchModel',
- state: {
- loading: false,
- data: [],
- total: 0,
- isShowCreateModal: false,
- chunk_id: '',
- chunkInfo: {},
- d_list: [],
- question: '',
- doc_ids: [],
- pagination: { page: 1, size: 30 },
- doc_id: '',
- },
- reducers: {
- updateState(state, { payload }) {
- return {
- ...state,
- ...payload,
- };
- },
- },
- subscriptions: {
- setup({ dispatch, history }) {
- history.listen((location) => {
- console.log(location);
- });
- },
- },
- effects: {
- *getKfList({ payload = {} }, { call, put }) {
- const { data, response } = yield call(
- kbService.get_document_list,
- payload,
- );
-
- const { retcode, data: res, retmsg } = data;
- if (retcode === 0) {
- yield put({
- type: 'updateState',
- payload: {
- d_list: res,
- },
- });
- }
- },
- *chunk_list({ payload = {} }, { call, put, select }) {
- const { question, doc_ids, pagination }: KSearchModelState = yield select(
- (state: any) => state.kSearchModel,
- );
- const { data } = yield call(kbService.retrieval_test, {
- ...payload,
- ...pagination,
- question,
- doc_ids,
- similarity_threshold: 0.1,
- });
- const { retcode, data: res, retmsg } = data;
- if (retcode === 0) {
- yield put({
- type: 'updateState',
- payload: {
- data: res.chunks,
- total: res.total,
- },
- });
- }
- },
- *switch_chunk({ payload = {} }, { call, put }) {
- const { data } = yield call(
- kbService.switch_chunk,
- omit(payload, ['kb_id']),
- );
- const { retcode } = data;
- if (retcode === 0) {
- yield put({
- type: 'chunk_list',
- payload: {
- kb_id: payload.kb_id,
- },
- });
- }
- },
- *rm_chunk({ payload = {} }, { call, put }) {
- const { data } = yield call(kbService.rm_chunk, {
- chunk_ids: payload.chunk_ids,
- });
- const { retcode, data: res, retmsg } = data;
- if (retcode === 0) {
- // TODO: Can be extracted
- yield put({
- type: 'chunk_list',
- payload: {
- kb_id: payload.kb_id,
- },
- });
- }
- },
- *get_chunk({ payload = {} }, { call, put }) {
- const { data, response } = yield call(kbService.get_chunk, payload);
- const { retcode, data: res, retmsg } = data;
- if (retcode === 0) {
- yield put({
- type: 'updateState',
- payload: {
- chunkInfo: res,
- },
- });
- }
- },
- *create_hunk({ payload = {} }, { call, put }) {
- yield put({
- type: 'updateState',
- payload: {
- loading: true,
- },
- });
- let service = kbService.create_chunk;
- if (payload.chunk_id) {
- service = kbService.set_chunk;
- }
- const { data } = yield call(service, payload);
- const { retcode } = data;
- yield put({
- type: 'updateState',
- payload: {
- loading: false,
- },
- });
- if (retcode === 0) {
- yield put({
- type: 'updateState',
- payload: {
- isShowCreateModal: false,
- },
- });
- }
- },
- },
-};
-export default model;
diff --git a/web/src/pages/add-knowledge/components/knowledge-setting/configuration.tsx b/web/src/pages/add-knowledge/components/knowledge-setting/configuration.tsx
new file mode 100644
index 000000000..6e71f8cab
--- /dev/null
+++ b/web/src/pages/add-knowledge/components/knowledge-setting/configuration.tsx
@@ -0,0 +1,217 @@
+import {
+ useFetchKnowledgeBaseConfiguration,
+ useFetchParserList,
+ useKnowledgeBaseId,
+ useSelectParserList,
+} from '@/hooks/knowledgeHook';
+import {
+ Button,
+ Divider,
+ Form,
+ Input,
+ Radio,
+ Select,
+ Space,
+ Typography,
+ Upload,
+ UploadFile,
+} from 'antd';
+import pick from 'lodash/pick';
+import { useCallback, useEffect, useMemo } from 'react';
+import { useDispatch, useSelector } from 'umi';
+
+import { useOneNamespaceEffectsLoading } from '@/hooks/storeHooks';
+import { IKnowledge } from '@/interfaces/database/knowledge';
+import { IThirdOAIModelCollection } from '@/interfaces/database/llm';
+import { PlusOutlined } from '@ant-design/icons';
+import styles from './index.less';
+
+const { Title } = Typography;
+const { Option } = Select;
+
+const Configuration = () => {
+ const [form] = Form.useForm();
+ const dispatch = useDispatch();
+ const knowledgeBaseId = useKnowledgeBaseId();
+ const loading = useOneNamespaceEffectsLoading('kSModel', ['updateKb']);
+
+ const llmInfo: IThirdOAIModelCollection = useSelector(
+ (state: any) => state.settingModel.llmInfo,
+ );
+ const knowledgeDetails: IKnowledge = useSelector(
+ (state: any) => state.kSModel.knowledgeDetails,
+ );
+
+ const normFile = (e: any) => {
+ if (Array.isArray(e)) {
+ return e;
+ }
+ return e?.fileList;
+ };
+
+ const parserList = useSelectParserList();
+
+ const embeddingModelOptions = useMemo(() => {
+ return Object.entries(llmInfo).map(([key, value]) => {
+ return {
+ label: key,
+ options: value.map((x) => ({
+ label: x.llm_name,
+ value: x.llm_name,
+ })),
+ };
+ });
+ }, [llmInfo]);
+
+ const onFinish = async (values: any) => {
+ console.info(values);
+ const fileList = values.avatar;
+ let avatar;
+
+ if (Array.isArray(fileList)) {
+ avatar = fileList[0].thumbUrl;
+ }
+
+ dispatch({
+ type: 'kSModel/updateKb',
+ payload: {
+ ...values,
+ avatar,
+ kb_id: knowledgeBaseId,
+ },
+ });
+ };
+
+ const onFinishFailed = (errorInfo: any) => {
+ console.log('Failed:', errorInfo);
+ };
+
+ const fetchLlmList = useCallback(() => {
+ dispatch({
+ type: 'settingModel/llm_list',
+ payload: { model_type: 'embedding' },
+ });
+ }, [dispatch]);
+
+ useEffect(() => {
+ const avatar = knowledgeDetails.avatar;
+ let fileList: UploadFile[] = [];
+
+ if (avatar) {
+ fileList = [{ uid: '1', name: 'file', thumbUrl: avatar, status: 'done' }];
+ }
+ form.setFieldsValue({
+ ...pick(knowledgeDetails, [
+ 'description',
+ 'name',
+ 'permission',
+ 'embd_id',
+ 'parser_id',
+ ]),
+ avatar: fileList,
+ });
+ }, [form, knowledgeDetails]);
+
+ useFetchParserList();
+ useFetchKnowledgeBaseConfiguration();
+
+ useEffect(() => {
+ fetchLlmList();
+ }, [fetchLlmList]);
+
+ return (
+
+
Configuration
+
Update your knowledge base details especially parsing method here.
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Only me
+ Team
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ );
+};
+
+export default Configuration;
diff --git a/web/src/pages/add-knowledge/components/knowledge-setting/index.less b/web/src/pages/add-knowledge/components/knowledge-setting/index.less
index 1c06588d5..0691fd904 100644
--- a/web/src/pages/add-knowledge/components/knowledge-setting/index.less
+++ b/web/src/pages/add-knowledge/components/knowledge-setting/index.less
@@ -1,24 +1,30 @@
.tags {
- margin-bottom: 24px;
+ margin-bottom: 24px;
}
.preset {
- display: flex;
- height: 80px;
- background-color: rgba(0, 0, 0, 0.1);
- border-radius: 5px;
+ display: flex;
+ height: 80px;
+ background-color: rgba(0, 0, 0, 0.1);
+ border-radius: 5px;
+ padding: 5px;
+ margin-bottom: 24px;
+
+ .left {
+ flex: 1;
+ }
+
+ .right {
+ width: 100px;
+ border-left: 1px solid rgba(0, 0, 0, 0.4);
+ margin: 10px 0px;
padding: 5px;
- margin-bottom: 24px;
+ }
+}
- .left {
- flex: 1;
-
- }
-
- .right {
- width: 100px;
- border-left: 1px solid rgba(0, 0, 0, 0.4);
- margin: 10px 0px;
- padding: 5px;
- }
-}
\ No newline at end of file
+.configurationWrapper {
+ padding: 0 52px;
+ .buttonWrapper {
+ text-align: right;
+ }
+}
diff --git a/web/src/pages/add-knowledge/components/knowledge-setting/index.tsx b/web/src/pages/add-knowledge/components/knowledge-setting/index.tsx
index 1926acb2a..74a0712d8 100644
--- a/web/src/pages/add-knowledge/components/knowledge-setting/index.tsx
+++ b/web/src/pages/add-knowledge/components/knowledge-setting/index.tsx
@@ -3,6 +3,8 @@ import { useKnowledgeBaseId } from '@/hooks/knowledgeHook';
import { Button, Form, Input, Radio, Select, Space, Tag } from 'antd';
import { useCallback, useEffect, useState } from 'react';
import { useDispatch, useNavigate, useSelector } from 'umi';
+import Configuration from './configuration';
+
import styles from './index.less';
const { CheckableTag } = Tag;
@@ -12,7 +14,6 @@ const layout = {
labelAlign: 'left' as const,
};
const { Option } = Select;
-/* eslint-disable no-template-curly-in-string */
const KnowledgeSetting = () => {
const dispatch = useDispatch();
@@ -44,7 +45,7 @@ const KnowledgeSetting = () => {
setSelectedTag(data.data.parser_id);
}
}
- }, [knowledgeBaseId]);
+ }, [knowledgeBaseId, dispatch, form]);
const onFinish = async () => {
try {
@@ -68,10 +69,11 @@ const KnowledgeSetting = () => {
parser_id: selectedTag,
},
});
- retcode === 0 &&
+ if (retcode === 0) {
navigate(
`/knowledge/${KnowledgeRouteKey.Dataset}?id=${knowledgeBaseId}`,
);
+ }
}
} catch (error) {
console.warn(error);
@@ -158,4 +160,6 @@ const KnowledgeSetting = () => {
);
};
-export default KnowledgeSetting;
+// export default KnowledgeSetting;
+
+export default Configuration;
diff --git a/web/src/pages/add-knowledge/components/knowledge-setting/model.ts b/web/src/pages/add-knowledge/components/knowledge-setting/model.ts
index 0cd548827..1f4499631 100644
--- a/web/src/pages/add-knowledge/components/knowledge-setting/model.ts
+++ b/web/src/pages/add-knowledge/components/knowledge-setting/model.ts
@@ -1,3 +1,4 @@
+import { IKnowledge } from '@/interfaces/database/knowledge';
import kbService from '@/services/kbService';
import { message } from 'antd';
import { DvaModel } from 'umi';
@@ -6,6 +7,7 @@ export interface KSModelState {
isShowPSwModal: boolean;
isShowTntModal: boolean;
tenantIfo: any;
+ knowledgeDetails: IKnowledge;
}
const model: DvaModel = {
@@ -14,6 +16,7 @@ const model: DvaModel = {
isShowPSwModal: false,
isShowTntModal: false,
tenantIfo: {},
+ knowledgeDetails: {} as any,
},
reducers: {
updateState(state, { payload }) {
@@ -22,31 +25,32 @@ const model: DvaModel = {
...payload,
};
},
- },
- subscriptions: {
- setup({ dispatch, history }) {
- history.listen((location) => {});
+ setKnowledgeDetails(state, { payload }) {
+ return { ...state, knowledgeDetails: payload };
},
},
effects: {
- *createKb({ payload = {} }, { call, put }) {
+ *createKb({ payload = {} }, { call }) {
const { data } = yield call(kbService.createKb, payload);
const { retcode } = data;
if (retcode === 0) {
- message.success('创建知识库成功!');
+ message.success('Created successfully!');
}
return data;
},
*updateKb({ payload = {} }, { call, put }) {
const { data } = yield call(kbService.updateKb, payload);
- const { retcode, data: res, retmsg } = data;
+ const { retcode } = data;
if (retcode === 0) {
- message.success('更新知识库成功!');
+ yield put({ type: 'getKbDetail', payload: { kb_id: payload.kb_id } });
+ message.success('Updated successfully!');
}
},
*getKbDetail({ payload = {} }, { call, put }) {
const { data } = yield call(kbService.get_kb_detail, payload);
-
+ if (data.retcode === 0) {
+ yield put({ type: 'setKnowledgeDetails', payload: data.data });
+ }
return data;
},
},
diff --git a/web/src/pages/add-knowledge/components/knowledge-sidebar/index.tsx b/web/src/pages/add-knowledge/components/knowledge-sidebar/index.tsx
index e24e0bf32..44805fd52 100644
--- a/web/src/pages/add-knowledge/components/knowledge-sidebar/index.tsx
+++ b/web/src/pages/add-knowledge/components/knowledge-sidebar/index.tsx
@@ -1,9 +1,10 @@
-import { ReactComponent as ConfigrationIcon } from '@/assets/svg/knowledge-configration.svg';
+import { ReactComponent as ConfigurationIcon } from '@/assets/svg/knowledge-configration.svg';
import { ReactComponent as DatasetIcon } from '@/assets/svg/knowledge-dataset.svg';
import { ReactComponent as TestingIcon } from '@/assets/svg/knowledge-testing.svg';
+import { useFetchKnowledgeBaseConfiguration } from '@/hooks/knowledgeHook';
import { useSecondPathName } from '@/hooks/routeHook';
+import { IKnowledge } from '@/interfaces/database/knowledge';
import { getWidth } from '@/utils';
-import { AntDesignOutlined } from '@ant-design/icons';
import { Avatar, Menu, MenuProps, Space } from 'antd';
import classNames from 'classnames';
import { useCallback, useEffect, useMemo, useState } from 'react';
@@ -16,6 +17,9 @@ const KnowledgeSidebar = () => {
const { id } = kAModel;
let navigate = useNavigate();
const activeKey = useSecondPathName();
+ const knowledgeDetails: IKnowledge = useSelector(
+ (state: any) => state.kSModel.knowledgeDetails,
+ );
const [windowWidth, setWindowWidth] = useState(getWidth());
const [collapsed, setCollapsed] = useState(false);
@@ -62,12 +66,7 @@ const KnowledgeSidebar = () => {
getItem(
routeMap[KnowledgeRouteKey.Configuration],
KnowledgeRouteKey.Configuration,
- ,
- ),
- getItem(
- routeMap[KnowledgeRouteKey.TempTesting],
- KnowledgeRouteKey.TempTesting,
- ,
+ ,
),
];
}, [getItem]);
@@ -93,16 +92,17 @@ const KnowledgeSidebar = () => {
};
}, []);
+ useFetchKnowledgeBaseConfiguration();
+
return (
- } />
- Cloud Computing
+
+ {knowledgeDetails.name}
- A scalable, secure cloud-based database optimized for high-performance
- computing and data storage.
+ {knowledgeDetails.description}
diff --git a/web/src/pages/setting/model.ts b/web/src/pages/setting/model.ts
index 4a843e9df..643ed5e71 100644
--- a/web/src/pages/setting/model.ts
+++ b/web/src/pages/setting/model.ts
@@ -1,4 +1,5 @@
import { ITenantInfo } from '@/interfaces/database/knowledge';
+import { IThirdOAIModelCollection as IThirdAiModelCollection } from '@/interfaces/database/llm';
import userService from '@/services/userService';
import authorizationUtil from '@/utils/authorizationUtil';
import { message } from 'antd';
@@ -12,7 +13,7 @@ export interface SettingModelState {
isShowSSModal: boolean;
llm_factory: string;
tenantIfo: Nullable
;
- llmInfo: any;
+ llmInfo: IThirdAiModelCollection;
myLlm: any[];
factoriesList: any[];
}
@@ -126,8 +127,8 @@ const model: DvaModel = {
}
},
*llm_list({ payload = {} }, { call, put }) {
- const { data, response } = yield call(userService.llm_list, payload);
- const { retcode, data: res, retmsg } = data;
+ const { data } = yield call(userService.llm_list, payload);
+ const { retcode, data: res } = data;
if (retcode === 0) {
yield put({
type: 'updateState',
diff --git a/web/src/routes.ts b/web/src/routes.ts
index c2f8aebcf..aff5178c4 100644
--- a/web/src/routes.ts
+++ b/web/src/routes.ts
@@ -44,10 +44,6 @@ const routes = [
},
{
path: '/knowledge/testing',
- component: '@/pages/add-knowledge/components/knowledge-search',
- },
- {
- path: '/knowledge/tempTesting',
component: '@/pages/add-knowledge/components/knowledge-testing',
},
],
diff --git a/web/src/utils/fileUtil.ts b/web/src/utils/fileUtil.ts
new file mode 100644
index 000000000..ab9cced01
--- /dev/null
+++ b/web/src/utils/fileUtil.ts
@@ -0,0 +1,28 @@
+export const transformFile2Base64 = (val: any): Promise => {
+ return new Promise((resolve, reject) => {
+ const reader = new FileReader();
+ reader.readAsDataURL(val);
+ reader.onload = (): void => {
+ resolve(reader.result);
+ };
+ reader.onerror = reject;
+ });
+};
+
+export const transformBase64ToFile = (
+ dataUrl: string,
+ filename: string = 'file',
+) => {
+ let arr = dataUrl.split(','),
+ bstr = atob(arr[1]),
+ n = bstr.length,
+ u8arr = new Uint8Array(n);
+
+ const mime = arr[0].match(/:(.*?);/);
+ const mimeType = mime ? mime[1] : 'image/png';
+
+ while (n--) {
+ u8arr[n] = bstr.charCodeAt(n);
+ }
+ return new File([u8arr], filename, { type: mimeType });
+};