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.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  1. import { LanguageTranslationMap } from '@/constants/common';
  2. import { ITenantInfo } from '@/interfaces/database/knowledge';
  3. import {
  4. IFactory,
  5. IMyLlmValue,
  6. IThirdOAIModelCollection as IThirdAiModelCollection,
  7. } from '@/interfaces/database/llm';
  8. import { IUserInfo } from '@/interfaces/database/userSetting';
  9. import i18n from '@/locales/config';
  10. import userService from '@/services/userService';
  11. import { message } from 'antd';
  12. import { DvaModel } from 'umi';
  13. export interface SettingModelState {
  14. llm_factory: string;
  15. tenantIfo: Nullable<ITenantInfo>;
  16. llmInfo: IThirdAiModelCollection;
  17. myLlmList: Record<string, IMyLlmValue>;
  18. factoryList: IFactory[];
  19. userInfo: IUserInfo;
  20. }
  21. const model: DvaModel<SettingModelState> = {
  22. namespace: 'settingModel',
  23. state: {
  24. llm_factory: '',
  25. tenantIfo: null,
  26. llmInfo: {},
  27. myLlmList: {},
  28. factoryList: [],
  29. userInfo: {} as IUserInfo,
  30. },
  31. reducers: {
  32. updateState(state, { payload }) {
  33. return {
  34. ...state,
  35. ...payload,
  36. };
  37. },
  38. setUserInfo(state, { payload }) {
  39. return {
  40. ...state,
  41. userInfo: payload,
  42. };
  43. },
  44. },
  45. effects: {
  46. *setting({ payload = {} }, { call, put }) {
  47. const { data } = yield call(userService.setting, payload);
  48. const { retcode } = data;
  49. if (retcode === 0) {
  50. message.success(i18n.t('message.modified'));
  51. yield put({
  52. type: 'getUserInfo',
  53. });
  54. }
  55. },
  56. *getUserInfo({ payload = {} }, { call, put }) {
  57. const { data } = yield call(userService.user_info, payload);
  58. const { retcode, data: res } = data;
  59. // const userInfo = {
  60. // avatar: res.avatar,
  61. // name: res.nickname,
  62. // email: res.email,
  63. // };
  64. // authorizationUtil.setUserInfo(userInfo);
  65. if (retcode === 0) {
  66. i18n.changeLanguage(
  67. LanguageTranslationMap[
  68. res.language as keyof typeof LanguageTranslationMap
  69. ],
  70. );
  71. yield put({ type: 'setUserInfo', payload: res });
  72. // localStorage.setItem('userInfo',res.)
  73. }
  74. },
  75. *getTenantInfo({ payload = {} }, { call, put }) {
  76. const { data } = yield call(userService.get_tenant_info, payload);
  77. const { retcode, data: res } = data;
  78. // llm_id 对应chat_id
  79. // asr_id 对应speech2txt
  80. if (retcode === 0) {
  81. res.chat_id = res.llm_id;
  82. res.speech2text_id = res.asr_id;
  83. yield put({
  84. type: 'updateState',
  85. payload: {
  86. tenantIfo: res,
  87. },
  88. });
  89. }
  90. },
  91. *set_tenant_info({ payload = {} }, { call, put }) {
  92. const { data } = yield call(userService.set_tenant_info, payload);
  93. const { retcode } = data;
  94. if (retcode === 0) {
  95. message.success(i18n.t('message.modified'));
  96. yield put({
  97. type: 'getTenantInfo',
  98. });
  99. }
  100. return retcode;
  101. },
  102. *factories_list({ payload = {} }, { call, put }) {
  103. const { data } = yield call(userService.factories_list);
  104. const { retcode, data: res } = data;
  105. if (retcode === 0) {
  106. yield put({
  107. type: 'updateState',
  108. payload: {
  109. factoryList: res,
  110. },
  111. });
  112. }
  113. },
  114. *llm_list({ payload = {} }, { call, put }) {
  115. const { data } = yield call(userService.llm_list, payload);
  116. const { retcode, data: res } = data;
  117. if (retcode === 0) {
  118. yield put({
  119. type: 'updateState',
  120. payload: {
  121. llmInfo: res,
  122. },
  123. });
  124. }
  125. },
  126. *my_llm({ payload = {} }, { call, put }) {
  127. const { data } = yield call(userService.my_llm);
  128. const { retcode, data: res } = data;
  129. if (retcode === 0) {
  130. yield put({
  131. type: 'updateState',
  132. payload: {
  133. myLlmList: res,
  134. },
  135. });
  136. }
  137. },
  138. *set_api_key({ payload = {} }, { call, put }) {
  139. const { data } = yield call(userService.set_api_key, payload);
  140. const { retcode } = data;
  141. if (retcode === 0) {
  142. message.success(i18n.t('message.modified'));
  143. yield put({ type: 'my_llm' });
  144. yield put({ type: 'factories_list' });
  145. yield put({
  146. type: 'updateState',
  147. });
  148. }
  149. return retcode;
  150. },
  151. *add_llm({ payload = {} }, { call, put }) {
  152. const { data } = yield call(userService.add_llm, payload);
  153. const { retcode } = data;
  154. if (retcode === 0) {
  155. message.success(i18n.t('message.modified'));
  156. yield put({ type: 'my_llm' });
  157. yield put({ type: 'factories_list' });
  158. }
  159. return retcode;
  160. },
  161. },
  162. };
  163. export default model;