You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

model.ts 1.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. import { BaseState } from '@/interfaces/common';
  2. import {
  3. ITestingChunk,
  4. ITestingDocument,
  5. } from '@/interfaces/database/knowledge';
  6. import kbService from '@/services/knowledge-service';
  7. import { DvaModel } from 'umi';
  8. export interface TestingModelState extends Pick<BaseState, 'pagination'> {
  9. chunks: ITestingChunk[];
  10. documents: ITestingDocument[];
  11. total: number;
  12. selectedDocumentIds: string[] | undefined;
  13. }
  14. const initialState = {
  15. chunks: [],
  16. documents: [],
  17. total: 0,
  18. pagination: {
  19. current: 1,
  20. pageSize: 10,
  21. },
  22. selectedDocumentIds: undefined,
  23. };
  24. const model: DvaModel<TestingModelState> = {
  25. namespace: 'testingModel',
  26. state: initialState,
  27. reducers: {
  28. setChunksAndDocuments(state, { payload }) {
  29. return {
  30. ...state,
  31. ...payload,
  32. };
  33. },
  34. setPagination(state, { payload }) {
  35. return { ...state, pagination: { ...state.pagination, ...payload } };
  36. },
  37. setSelectedDocumentIds(state, { payload }) {
  38. return { ...state, selectedDocumentIds: payload };
  39. },
  40. reset() {
  41. return initialState;
  42. },
  43. },
  44. effects: {
  45. *testDocumentChunk({ payload = {} }, { call, put, select }) {
  46. const { pagination, selectedDocumentIds }: TestingModelState =
  47. yield select((state: any) => state.testingModel);
  48. const { data } = yield call(kbService.retrieval_test, {
  49. ...payload,
  50. doc_ids: selectedDocumentIds,
  51. page: pagination.current,
  52. size: pagination.pageSize,
  53. });
  54. const { retcode, data: res } = data;
  55. if (retcode === 0) {
  56. yield put({
  57. type: 'setChunksAndDocuments',
  58. payload: {
  59. chunks: res.chunks,
  60. documents: res.doc_aggs,
  61. total: res.total,
  62. },
  63. });
  64. }
  65. },
  66. },
  67. };
  68. export default model;