feat: use DvaModel instead of redundant types such as kAModelType

This commit is contained in:
billchen 2024-01-30 10:52:29 +08:00
parent f2bdc1ef67
commit 4edfdad342
10 changed files with 180 additions and 312 deletions

View file

@ -1,7 +1,7 @@
import kbService from '@/services/kbService';
import { Effect, Reducer } from 'umi';
import { DvaModel } from 'umi';
export interface chunkModelState {
export interface ChunkModelState {
loading: boolean;
data: any[];
total: number;
@ -10,22 +10,8 @@ export interface chunkModelState {
doc_id: string;
chunkInfo: any;
}
export interface chunkgModelType {
namespace: 'chunkModel';
state: chunkModelState;
effects: {
chunk_list: Effect;
get_chunk: Effect;
create_hunk: Effect;
switch_chunk: Effect;
rm_chunk: Effect;
};
reducers: {
updateState: Reducer<chunkModelState>;
};
// subscriptions: { setup: Subscription };
}
const Model: chunkgModelType = {
const model: DvaModel<ChunkModelState> = {
namespace: 'chunkModel',
state: {
loading: false,
@ -36,6 +22,14 @@ const Model: chunkgModelType = {
doc_id: '',
chunkInfo: {},
},
reducers: {
updateState(state, { payload }) {
return {
...state,
...payload,
};
},
},
// subscriptions: {
// setup({ dispatch, history }) {
// history.listen(location => {
@ -118,13 +112,5 @@ const Model: chunkgModelType = {
}
},
},
reducers: {
updateState(state, { payload }) {
return {
...state,
...payload,
};
},
},
};
export default Model;
export default model;

View file

@ -1,8 +1,8 @@
import kbService from '@/services/kbService';
import { message } from 'antd';
import { Effect, Reducer, Subscription } from 'umi';
import { DvaModel } from 'umi';
export interface kFModelState {
export interface KFModelState {
isShowCEFwModal: boolean;
isShowTntModal: boolean;
isShowSegmentSetModal: boolean;
@ -10,25 +10,8 @@ export interface kFModelState {
tenantIfo: any;
data: any[];
}
export interface kFModelType {
namespace: 'kFModel';
state: kFModelState;
effects: {
createKf: Effect;
updateKf: Effect;
getKfDetail: Effect;
getKfList: Effect;
updateDocumentStatus: Effect;
document_rm: Effect;
document_create: Effect;
document_change_parser: Effect;
};
reducers: {
updateState: Reducer<kFModelState>;
};
subscriptions: { setup: Subscription };
}
const Model: kFModelType = {
const model: DvaModel<KFModelState> = {
namespace: 'kFModel',
state: {
isShowCEFwModal: false,
@ -38,6 +21,14 @@ const Model: kFModelType = {
tenantIfo: {},
data: [],
},
reducers: {
updateState(state, { payload }) {
return {
...state,
...payload,
};
},
},
subscriptions: {
setup({ dispatch, history }) {
history.listen((location) => {});
@ -144,13 +135,5 @@ const Model: kFModelType = {
}
},
},
reducers: {
updateState(state, { payload }) {
return {
...state,
...payload,
};
},
},
};
export default Model;
export default model;

View file

@ -1,8 +1,7 @@
import { Effect, Reducer, Subscription } from 'umi'
import { message } from 'antd';
import kbService from '@/services/kbService';
import { DvaModel } from 'umi';
export interface kSearchModelState {
export interface KSearchModelState {
loading: boolean;
data: any[];
total: number;
@ -13,26 +12,10 @@ export interface kSearchModelState {
question: string;
doc_ids: any[];
pagination: any;
doc_id: string
doc_id: string;
}
}
export interface chunkgModelType {
namespace: 'kSearchModel';
state: kSearchModelState;
effects: {
chunk_list: Effect;
get_chunk: Effect;
create_hunk: Effect;
switch_chunk: Effect;
rm_chunk: Effect;
getKfList: Effect;
};
reducers: {
updateState: Reducer<kSearchModelState>;
};
subscriptions: { setup: Subscription };
}
const Model: chunkgModelType = {
const model: DvaModel<KSearchModelState> = {
namespace: 'kSearchModel',
state: {
loading: false,
@ -45,114 +28,112 @@ const Model: chunkgModelType = {
question: '',
doc_ids: [],
pagination: { page: 1, size: 30 },
doc_id: ''
doc_id: '',
},
reducers: {
updateState(state, { payload }) {
return {
...state,
...payload,
};
},
},
subscriptions: {
setup({ dispatch, history }) {
history.listen(location => {
console.log(location)
history.listen((location) => {
console.log(location);
});
}
},
},
effects: {
*getKfList({ payload = {} }, { call, put }) {
const { data, response } = yield call(kbService.get_document_list, payload);
const { data, response } = yield call(
kbService.get_document_list,
payload,
);
const { retcode, data: res, retmsg } = data
const { retcode, data: res, retmsg } = data;
if (retcode === 0) {
yield put({
type: 'updateState',
payload: {
d_list: res
}
d_list: res,
},
});
}
},
* chunk_list({ payload = {}, callback }, { call, put }) {
*chunk_list({ payload = {}, callback }, { call, put }) {
const { data, response } = yield call(kbService.retrieval_test, payload);
const { retcode, data: res, retmsg } = data
const { retcode, data: res, retmsg } = data;
if (retcode === 0) {
console.log(res)
console.log(res);
yield put({
type: 'updateState',
payload: {
data: res.chunks,
total: res.total,
loading: false
}
loading: false,
},
});
callback && callback()
callback && callback();
}
},
*switch_chunk({ payload = {}, callback }, { call, put }) {
const { data, response } = yield call(kbService.switch_chunk, payload);
const { retcode, data: res, retmsg } = data
const { retcode, data: res, retmsg } = data;
if (retcode === 0) {
callback && callback()
callback && callback();
}
},
*rm_chunk({ payload = {}, callback }, { call, put }) {
console.log('shanchu')
console.log('shanchu');
const { data, response } = yield call(kbService.rm_chunk, payload);
const { retcode, data: res, retmsg } = data
const { retcode, data: res, retmsg } = data;
if (retcode === 0) {
callback && callback()
callback && callback();
}
},
* get_chunk({ payload = {}, callback }, { call, put }) {
*get_chunk({ payload = {}, callback }, { call, put }) {
const { data, response } = yield call(kbService.get_chunk, payload);
const { retcode, data: res, retmsg } = data
const { retcode, data: res, retmsg } = data;
if (retcode === 0) {
yield put({
type: 'updateState',
payload: {
chunkInfo: res
}
chunkInfo: res,
},
});
callback && callback(res)
callback && callback(res);
}
},
*create_hunk({ payload = {} }, { call, put }) {
yield put({
type: 'updateState',
payload: {
loading: true
}
loading: true,
},
});
let service = kbService.create_chunk
let service = kbService.create_chunk;
if (payload.chunk_id) {
service = kbService.set_chunk
service = kbService.set_chunk;
}
const { data, response } = yield call(service, payload);
const { retcode, data: res, retmsg } = data
const { retcode, data: res, retmsg } = data;
yield put({
type: 'updateState',
payload: {
loading: false
}
loading: false,
},
});
if (retcode === 0) {
yield put({
type: 'updateState',
payload: {
isShowCreateModal: false
}
isShowCreateModal: false,
},
});
}
},
},
reducers: {
updateState(state, { payload }) {
return {
...state,
...payload
};
}
}
};
export default Model;
export default model;

View file

@ -1,72 +1,59 @@
import { message } from 'antd';
import { Effect, Reducer, Subscription } from 'umi'
import kbService from '@/services/kbService';
import { message } from 'antd';
import { DvaModel } from 'umi';
export interface kSModelState {
export interface KSModelState {
isShowPSwModal: boolean;
isShowTntModal: boolean;
loading: boolean;
tenantIfo: any
tenantIfo: any;
}
export interface kSModelType {
namespace: 'kSModel';
state: kSModelState;
effects: {
createKb: Effect;
updateKb: Effect;
getKbDetail: Effect;
};
reducers: {
updateState: Reducer<kSModelState>;
};
subscriptions: { setup: Subscription };
}
const Model: kSModelType = {
const model: DvaModel<KSModelState> = {
namespace: 'kSModel',
state: {
isShowPSwModal: false,
isShowTntModal: false,
loading: false,
tenantIfo: {}
tenantIfo: {},
},
reducers: {
updateState(state, { payload }) {
return {
...state,
...payload,
};
},
},
subscriptions: {
setup({ dispatch, history }) {
history.listen(location => {
});
}
history.listen((location) => {});
},
},
effects: {
* createKb({ payload = {}, callback }, { call, put }) {
*createKb({ payload = {}, callback }, { call, put }) {
const { data, response } = yield call(kbService.createKb, payload);
const { retcode, data: res, retmsg } = data
const { retcode, data: res, retmsg } = data;
if (retcode === 0) {
message.success('创建知识库成功!');
callback && callback(res.kb_id)
callback && callback(res.kb_id);
}
},
* updateKb({ payload = {}, callback }, { call, put }) {
*updateKb({ payload = {}, callback }, { call, put }) {
const { data, response } = yield call(kbService.updateKb, payload);
const { retcode, data: res, retmsg } = data
const { retcode, data: res, retmsg } = data;
if (retcode === 0) {
message.success('更新知识库成功!');
}
},
*getKbDetail({ payload = {}, callback }, { call, put }) {
const { data, response } = yield call(kbService.get_kb_detail, payload);
const { retcode, data: res, retmsg } = data
const { retcode, data: res, retmsg } = data;
if (retcode === 0) {
// localStorage.setItem('userInfo',res.)
callback && callback(res)
callback && callback(res);
}
},
},
reducers: {
updateState(state, { payload }) {
return {
...state,
...payload
};
}
}
};
export default Model;
export default model;

View file

@ -1,6 +1,4 @@
import { Effect, Reducer, Subscription } from 'umi'
import { message } from 'antd';
import kbService from '@/services/kbService';
import { DvaModel } from 'umi';
export interface kAModelState {
isShowPSwModal: boolean;
isShowTntModal: boolean;
@ -8,20 +6,10 @@ export interface kAModelState {
tenantIfo: any;
activeKey: string;
id: string;
doc_id: string
doc_id: string;
}
export interface kAModelType {
namespace: 'kAModel';
state: kAModelState;
effects: {
};
reducers: {
updateState: Reducer<kAModelState>;
};
subscriptions: { setup: Subscription };
}
const Model: kAModelType = {
const model: DvaModel<kAModelState> = {
namespace: 'kAModel',
state: {
isShowPSwModal: false,
@ -30,25 +18,21 @@ const Model: kAModelType = {
tenantIfo: {},
activeKey: 'setting',
id: '',
doc_id: ''
},
subscriptions: {
setup({ dispatch, history }) {
history.listen(location => {
});
}
},
effects: {
doc_id: '',
},
reducers: {
updateState(state, { payload }) {
return {
...state,
...payload
...payload,
};
}
}
},
},
subscriptions: {
setup({ dispatch, history }) {
history.listen((location) => {});
},
},
effects: {},
};
export default Model;
export default model;

View file

@ -1,46 +1,32 @@
import { Effect, Reducer, Subscription } from 'umi';
import { DvaModel } from 'umi';
export interface chatModelState {
name: string;
export interface ChatModelState {
name: string;
}
export interface chatModelType {
namespace: 'chatModel';
state: chatModelState;
effects: {
query: Effect;
};
reducers: {
save: Reducer<chatModelState>;
};
subscriptions: { setup: Subscription };
}
const Model: chatModelType = {
namespace: 'chatModel',
state: {
name: 'kate',
const model: DvaModel<ChatModelState> = {
namespace: 'chatModel',
state: {
name: 'kate',
},
reducers: {
save(state, action) {
return {
...state,
...action.payload,
};
},
effects: {
*query({ payload }, { call, put }) { },
},
reducers: {
save(state, action) {
return {
...state,
...action.payload,
};
},
},
subscriptions: {
setup({ dispatch, history }) {
return history.listen((query) => {
console.log(query)
});
},
},
effects: {
*query({ payload }, { call, put }) {},
},
subscriptions: {
setup({ dispatch, history }) {
return history.listen((query) => {
console.log(query);
});
},
},
};
export default Model;
export default model;

View file

@ -1,28 +1,25 @@
import kbService from '@/services/kbService';
import { Effect, Reducer } from 'umi';
import { DvaModel } from 'umi';
export interface knowledgeModelState {
export interface KnowledgeModelState {
loading: boolean;
data: any[];
}
export interface knowledgegModelType {
namespace: 'knowledgeModel';
state: knowledgeModelState;
effects: {
rmKb: Effect;
getList: Effect;
};
reducers: {
updateState: Reducer<knowledgeModelState>;
};
// subscriptions: { setup: Subscription };
}
const Model: knowledgegModelType = {
const model: DvaModel<KnowledgeModelState> = {
namespace: 'knowledgeModel',
state: {
loading: false,
data: [],
},
reducers: {
updateState(state, { payload }) {
return {
...state,
...payload,
};
},
},
// subscriptions: {
// setup({ dispatch, history }) {
// history.listen((location) => {
@ -63,13 +60,5 @@ const Model: knowledgegModelType = {
}
},
},
reducers: {
updateState(state, { payload }) {
return {
...state,
...payload,
};
},
},
};
export default Model;
export default model;

View file

@ -10,6 +10,7 @@ interface LoginProps {
const View: FC<LoginProps> = ({ dispatch }) => {
let navigate = useNavigate();
const [title, setTitle] = useState('login');
const changeTitle = () => {
setTitle((title) => (title === 'login' ? 'register' : 'login'));
};
@ -106,7 +107,7 @@ const View: FC<LoginProps> = ({ dispatch }) => {
label="Password"
rules={[{ required: true, message: 'Please input value' }]}
>
<Input size="large" placeholder="Please input value" />
<Input.Password size="large" placeholder="Please input value" />
</Form.Item>
{title === 'login' && (
<Form.Item name="remember" valuePropName="checked">

View file

@ -2,32 +2,29 @@ import { Authorization } from '@/constants/authorization';
import userService from '@/services/userService';
import authorizationUtil from '@/utils/authorizationUtil';
import { message } from 'antd';
import { Effect, Reducer, Subscription } from 'umi';
import { DvaModel } from 'umi';
export interface loginModelState {
export interface LoginModelState {
list: any[];
info: any;
visible: boolean;
}
export interface logingModelType {
namespace: 'loginModel';
state: loginModelState;
effects: {
login: Effect;
register: Effect;
};
reducers: {
updateState: Reducer<loginModelState>;
};
subscriptions: { setup: Subscription };
}
const Model: logingModelType = {
const model: DvaModel<LoginModelState> = {
namespace: 'loginModel',
state: {
list: [],
info: {},
visible: false,
},
reducers: {
updateState(state, { payload }) {
return {
...state,
...payload,
};
},
},
subscriptions: {
setup({ dispatch, history }) {
history.listen((location) => {});
@ -69,13 +66,5 @@ const Model: logingModelType = {
}
},
},
reducers: {
updateState(state, { payload }) {
return {
...state,
...payload,
};
},
},
};
export default Model;
export default model;

View file

@ -1,9 +1,9 @@
import userService from '@/services/userService';
import authorizationUtil from '@/utils/authorizationUtil';
import { message } from 'antd';
import { Effect, Reducer, Subscription } from 'umi';
import { DvaModel } from 'umi';
export interface settingModelState {
export interface SettingModelState {
isShowPSwModal: boolean;
isShowTntModal: boolean;
isShowSAKModal: boolean;
@ -16,25 +16,7 @@ export interface settingModelState {
factoriesList: any[];
}
export interface settingModelType {
namespace: 'settingModel';
state: settingModelState;
effects: {
setting: Effect;
getUserInfo: Effect;
getTenantInfo: Effect;
set_tenant_info: Effect;
factories_list: Effect;
llm_list: Effect;
my_llm: Effect;
set_api_key: Effect;
};
reducers: {
updateState: Reducer<settingModelState>;
};
subscriptions: { setup: Subscription };
}
const Model: settingModelType = {
const model: DvaModel<SettingModelState> = {
namespace: 'settingModel',
state: {
isShowPSwModal: false,
@ -48,6 +30,14 @@ const Model: settingModelType = {
myLlm: [],
factoriesList: [],
},
reducers: {
updateState(state, { payload }) {
return {
...state,
...payload,
};
},
},
subscriptions: {
setup({ dispatch, history }) {
history.listen((location) => {});
@ -176,13 +166,5 @@ const Model: settingModelType = {
}
},
},
reducers: {
updateState(state, { payload }) {
return {
...state,
...payload,
};
},
},
};
export default Model;
export default model;