File size: 1,819 Bytes
1a156e6
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
import { BaseState } from '@/interfaces/common';
import {
  ITestingChunk,
  ITestingDocument,
} from '@/interfaces/database/knowledge';
import kbService from '@/services/kbService';
import { DvaModel } from 'umi';

export interface TestingModelState extends Pick<BaseState, 'pagination'> {
  chunks: ITestingChunk[];
  documents: ITestingDocument[];
  total: number;
  selectedDocumentIds: string[] | undefined;
}

const initialState = {
  chunks: [],
  documents: [],
  total: 0,
  pagination: {
    current: 1,
    pageSize: 10,
  },
  selectedDocumentIds: undefined,
};

const model: DvaModel<TestingModelState> = {
  namespace: 'testingModel',
  state: initialState,
  reducers: {
    setChunksAndDocuments(state, { payload }) {
      return {
        ...state,
        ...payload,
      };
    },
    setPagination(state, { payload }) {
      return { ...state, pagination: { ...state.pagination, ...payload } };
    },
    setSelectedDocumentIds(state, { payload }) {
      return { ...state, selectedDocumentIds: payload };
    },
    reset() {
      return initialState;
    },
  },
  effects: {
    *testDocumentChunk({ payload = {} }, { call, put, select }) {
      const { pagination, selectedDocumentIds }: TestingModelState =
        yield select((state: any) => state.testingModel);

      const { data } = yield call(kbService.retrieval_test, {
        ...payload,
        doc_ids: selectedDocumentIds,
        page: pagination.current,
        size: pagination.pageSize,
      });
      const { retcode, data: res } = data;
      if (retcode === 0) {
        yield put({
          type: 'setChunksAndDocuments',
          payload: {
            chunks: res.chunks,
            documents: res.doc_aggs,
            total: res.total,
          },
        });
      }
    },
  },
};
export default model;