balibabu
commited on
Commit
·
3c31ff9
1
Parent(s):
e878c81
fix: fetch llm list by @tanstack/react-query #1306 (#1708)
Browse files### What problem does this PR solve?
fix: fetch llm list by @tanstack/react-query #1306
### Type of change
- [x] Bug Fix (non-breaking change which fixes an issue)
- web/src/hooks/llm-hooks.ts +134 -117
- web/src/hooks/logic-hooks.ts +0 -11
- web/src/interfaces/database/base.ts +5 -0
- web/src/pages/add-knowledge/components/knowledge-setting/hooks.ts +1 -3
- web/src/pages/add-knowledge/components/knowledge-testing/testing-control/index.tsx +3 -10
- web/src/pages/chat/chat-configuration-modal/index.tsx +5 -14
- web/src/pages/chat/index.tsx +11 -9
- web/src/pages/flow/hooks.ts +0 -3
- web/src/pages/user-setting/setting-model/hooks.ts +8 -30
- web/src/pages/user-setting/setting-model/index.tsx +2 -9
web/src/hooks/llm-hooks.ts
CHANGED
|
@@ -1,37 +1,37 @@
|
|
| 1 |
import { LlmModelType } from '@/constants/knowledge';
|
|
|
|
| 2 |
import {
|
| 3 |
IFactory,
|
| 4 |
IMyLlmValue,
|
|
|
|
| 5 |
IThirdOAIModelCollection,
|
| 6 |
} from '@/interfaces/database/llm';
|
| 7 |
import {
|
| 8 |
IAddLlmRequestBody,
|
| 9 |
IDeleteLlmRequestBody,
|
| 10 |
} from '@/interfaces/request/llm';
|
|
|
|
| 11 |
import { sortLLmFactoryListBySpecifiedOrder } from '@/utils/common-util';
|
| 12 |
-
import {
|
| 13 |
-
import {
|
|
|
|
|
|
|
|
|
|
| 14 |
|
| 15 |
export const useFetchLlmList = (
|
| 16 |
modelType?: LlmModelType,
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
}
|
| 26 |
-
}
|
| 27 |
-
|
| 28 |
-
useEffect(() => {
|
| 29 |
-
if (isOnMountFetching) {
|
| 30 |
-
fetchLlmList();
|
| 31 |
-
}
|
| 32 |
-
}, [fetchLlmList, isOnMountFetching]);
|
| 33 |
|
| 34 |
-
return
|
| 35 |
};
|
| 36 |
|
| 37 |
export const useSelectLlmInfo = () => {
|
|
@@ -43,7 +43,7 @@ export const useSelectLlmInfo = () => {
|
|
| 43 |
};
|
| 44 |
|
| 45 |
export const useSelectLlmOptions = () => {
|
| 46 |
-
const llmInfo: IThirdOAIModelCollection =
|
| 47 |
|
| 48 |
const embeddingModelOptions = useMemo(() => {
|
| 49 |
return Object.entries(llmInfo).map(([key, value]) => {
|
|
@@ -62,7 +62,7 @@ export const useSelectLlmOptions = () => {
|
|
| 62 |
};
|
| 63 |
|
| 64 |
export const useSelectLlmOptionsByModelType = () => {
|
| 65 |
-
const llmInfo: IThirdOAIModelCollection =
|
| 66 |
|
| 67 |
const groupOptionsByModelType = (modelType: LlmModelType) => {
|
| 68 |
return Object.entries(llmInfo)
|
|
@@ -96,73 +96,65 @@ export const useSelectLlmOptionsByModelType = () => {
|
|
| 96 |
};
|
| 97 |
};
|
| 98 |
|
| 99 |
-
export const
|
| 100 |
-
const
|
| 101 |
-
|
| 102 |
-
|
| 103 |
-
|
| 104 |
-
|
| 105 |
-
};
|
| 106 |
|
| 107 |
-
|
| 108 |
-
|
| 109 |
-
|
| 110 |
-
);
|
| 111 |
|
| 112 |
-
return
|
| 113 |
};
|
| 114 |
|
| 115 |
-
export
|
| 116 |
-
const dispatch = useDispatch();
|
| 117 |
-
const factoryList = useSelectLlmFactoryList();
|
| 118 |
-
const myLlmList = useSelectMyLlmList();
|
| 119 |
-
|
| 120 |
-
const list = useMemo(() => {
|
| 121 |
-
const currentList = factoryList.filter((x) =>
|
| 122 |
-
Object.keys(myLlmList).every((y) => y !== x.name),
|
| 123 |
-
);
|
| 124 |
-
return sortLLmFactoryListBySpecifiedOrder(currentList);
|
| 125 |
-
}, [factoryList, myLlmList]);
|
| 126 |
-
|
| 127 |
-
const fetchLlmFactoryList = useCallback(() => {
|
| 128 |
-
dispatch({
|
| 129 |
-
type: 'settingModel/factories_list',
|
| 130 |
-
});
|
| 131 |
-
}, [dispatch]);
|
| 132 |
|
| 133 |
-
|
| 134 |
-
|
| 135 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 136 |
|
| 137 |
-
return
|
| 138 |
};
|
| 139 |
|
| 140 |
-
export
|
|
|
|
|
|
|
|
|
|
| 141 |
|
| 142 |
-
|
| 143 |
-
|
| 144 |
-
const llmList = useSelectMyLlmList();
|
| 145 |
-
const factoryList = useSelectLlmFactoryList();
|
| 146 |
-
|
| 147 |
-
const list: Array<LlmItem> = useMemo(() => {
|
| 148 |
-
return Object.entries(llmList).map(([key, value]) => ({
|
| 149 |
name: key,
|
| 150 |
logo: factoryList.find((x) => x.name === key)?.logo ?? '',
|
| 151 |
...value,
|
| 152 |
}));
|
| 153 |
-
}, [
|
| 154 |
|
| 155 |
-
const
|
| 156 |
-
|
| 157 |
-
|
| 158 |
-
|
| 159 |
-
|
| 160 |
-
|
| 161 |
-
useEffect(() => {
|
| 162 |
-
fetchMyLlmList();
|
| 163 |
-
}, [fetchMyLlmList]);
|
| 164 |
|
| 165 |
-
return
|
|
|
|
|
|
|
|
|
|
|
|
|
| 166 |
};
|
| 167 |
|
| 168 |
export interface IApiKeySavingParams {
|
|
@@ -174,19 +166,26 @@ export interface IApiKeySavingParams {
|
|
| 174 |
}
|
| 175 |
|
| 176 |
export const useSaveApiKey = () => {
|
| 177 |
-
const
|
| 178 |
-
|
| 179 |
-
const
|
| 180 |
-
|
| 181 |
-
|
| 182 |
-
|
| 183 |
-
|
| 184 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 185 |
},
|
| 186 |
-
|
| 187 |
-
);
|
| 188 |
|
| 189 |
-
return saveApiKey;
|
| 190 |
};
|
| 191 |
|
| 192 |
export interface ISystemModelSettingSavingParams {
|
|
@@ -199,49 +198,67 @@ export interface ISystemModelSettingSavingParams {
|
|
| 199 |
}
|
| 200 |
|
| 201 |
export const useSaveTenantInfo = () => {
|
| 202 |
-
const
|
| 203 |
-
|
| 204 |
-
|
| 205 |
-
|
| 206 |
-
|
| 207 |
-
|
| 208 |
-
|
| 209 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 210 |
},
|
| 211 |
-
|
| 212 |
-
);
|
| 213 |
|
| 214 |
-
return saveTenantInfo;
|
| 215 |
};
|
| 216 |
|
| 217 |
export const useAddLlm = () => {
|
| 218 |
-
const
|
| 219 |
-
|
| 220 |
-
const
|
| 221 |
-
|
| 222 |
-
|
| 223 |
-
|
| 224 |
-
|
| 225 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 226 |
},
|
| 227 |
-
|
| 228 |
-
);
|
| 229 |
|
| 230 |
-
return addLlm;
|
| 231 |
};
|
| 232 |
|
| 233 |
export const useDeleteLlm = () => {
|
| 234 |
-
const
|
| 235 |
-
|
| 236 |
-
const
|
| 237 |
-
|
| 238 |
-
|
| 239 |
-
|
| 240 |
-
|
| 241 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 242 |
},
|
| 243 |
-
|
| 244 |
-
);
|
| 245 |
|
| 246 |
-
return deleteLlm;
|
| 247 |
};
|
|
|
|
| 1 |
import { LlmModelType } from '@/constants/knowledge';
|
| 2 |
+
import { ResponseGetType } from '@/interfaces/database/base';
|
| 3 |
import {
|
| 4 |
IFactory,
|
| 5 |
IMyLlmValue,
|
| 6 |
+
IThirdOAIModelCollection as IThirdAiModelCollection,
|
| 7 |
IThirdOAIModelCollection,
|
| 8 |
} from '@/interfaces/database/llm';
|
| 9 |
import {
|
| 10 |
IAddLlmRequestBody,
|
| 11 |
IDeleteLlmRequestBody,
|
| 12 |
} from '@/interfaces/request/llm';
|
| 13 |
+
import userService from '@/services/user-service';
|
| 14 |
import { sortLLmFactoryListBySpecifiedOrder } from '@/utils/common-util';
|
| 15 |
+
import { useMutation, useQuery, useQueryClient } from '@tanstack/react-query';
|
| 16 |
+
import { message } from 'antd';
|
| 17 |
+
import { useMemo } from 'react';
|
| 18 |
+
import { useTranslation } from 'react-i18next';
|
| 19 |
+
import { useSelector } from 'umi';
|
| 20 |
|
| 21 |
export const useFetchLlmList = (
|
| 22 |
modelType?: LlmModelType,
|
| 23 |
+
): IThirdAiModelCollection => {
|
| 24 |
+
const { data } = useQuery({
|
| 25 |
+
queryKey: ['llmList'],
|
| 26 |
+
initialData: {},
|
| 27 |
+
queryFn: async () => {
|
| 28 |
+
const { data } = await userService.llm_list({ model_type: modelType });
|
| 29 |
+
|
| 30 |
+
return data?.data ?? {};
|
| 31 |
+
},
|
| 32 |
+
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 33 |
|
| 34 |
+
return data;
|
| 35 |
};
|
| 36 |
|
| 37 |
export const useSelectLlmInfo = () => {
|
|
|
|
| 43 |
};
|
| 44 |
|
| 45 |
export const useSelectLlmOptions = () => {
|
| 46 |
+
const llmInfo: IThirdOAIModelCollection = useFetchLlmList();
|
| 47 |
|
| 48 |
const embeddingModelOptions = useMemo(() => {
|
| 49 |
return Object.entries(llmInfo).map(([key, value]) => {
|
|
|
|
| 62 |
};
|
| 63 |
|
| 64 |
export const useSelectLlmOptionsByModelType = () => {
|
| 65 |
+
const llmInfo: IThirdOAIModelCollection = useFetchLlmList();
|
| 66 |
|
| 67 |
const groupOptionsByModelType = (modelType: LlmModelType) => {
|
| 68 |
return Object.entries(llmInfo)
|
|
|
|
| 96 |
};
|
| 97 |
};
|
| 98 |
|
| 99 |
+
export const useFetchLlmFactoryList = (): ResponseGetType<IFactory[]> => {
|
| 100 |
+
const { data, isFetching: loading } = useQuery({
|
| 101 |
+
queryKey: ['factoryList'],
|
| 102 |
+
initialData: [],
|
| 103 |
+
gcTime: 0,
|
| 104 |
+
queryFn: async () => {
|
| 105 |
+
const { data } = await userService.factories_list();
|
| 106 |
|
| 107 |
+
return data?.data ?? [];
|
| 108 |
+
},
|
| 109 |
+
});
|
|
|
|
| 110 |
|
| 111 |
+
return { data, loading };
|
| 112 |
};
|
| 113 |
|
| 114 |
+
export type LlmItem = { name: string; logo: string } & IMyLlmValue;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 115 |
|
| 116 |
+
export const useFetchMyLlmList = (): ResponseGetType<
|
| 117 |
+
Record<string, IMyLlmValue>
|
| 118 |
+
> => {
|
| 119 |
+
const { data, isFetching: loading } = useQuery({
|
| 120 |
+
queryKey: ['myLlmList'],
|
| 121 |
+
initialData: {},
|
| 122 |
+
gcTime: 0,
|
| 123 |
+
queryFn: async () => {
|
| 124 |
+
const { data } = await userService.my_llm();
|
| 125 |
+
|
| 126 |
+
return data?.data ?? {};
|
| 127 |
+
},
|
| 128 |
+
});
|
| 129 |
|
| 130 |
+
return { data, loading };
|
| 131 |
};
|
| 132 |
|
| 133 |
+
export const useSelectLlmList = () => {
|
| 134 |
+
const { data: myLlmList, loading: myLlmListLoading } = useFetchMyLlmList();
|
| 135 |
+
const { data: factoryList, loading: factoryListLoading } =
|
| 136 |
+
useFetchLlmFactoryList();
|
| 137 |
|
| 138 |
+
const nextMyLlmList: Array<LlmItem> = useMemo(() => {
|
| 139 |
+
return Object.entries(myLlmList).map(([key, value]) => ({
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 140 |
name: key,
|
| 141 |
logo: factoryList.find((x) => x.name === key)?.logo ?? '',
|
| 142 |
...value,
|
| 143 |
}));
|
| 144 |
+
}, [myLlmList, factoryList]);
|
| 145 |
|
| 146 |
+
const nextFactoryList = useMemo(() => {
|
| 147 |
+
const currentList = factoryList.filter((x) =>
|
| 148 |
+
Object.keys(myLlmList).every((y) => y !== x.name),
|
| 149 |
+
);
|
| 150 |
+
return sortLLmFactoryListBySpecifiedOrder(currentList);
|
| 151 |
+
}, [factoryList, myLlmList]);
|
|
|
|
|
|
|
|
|
|
| 152 |
|
| 153 |
+
return {
|
| 154 |
+
myLlmList: nextMyLlmList,
|
| 155 |
+
factoryList: nextFactoryList,
|
| 156 |
+
loading: myLlmListLoading || factoryListLoading,
|
| 157 |
+
};
|
| 158 |
};
|
| 159 |
|
| 160 |
export interface IApiKeySavingParams {
|
|
|
|
| 166 |
}
|
| 167 |
|
| 168 |
export const useSaveApiKey = () => {
|
| 169 |
+
const queryClient = useQueryClient();
|
| 170 |
+
const { t } = useTranslation();
|
| 171 |
+
const {
|
| 172 |
+
data,
|
| 173 |
+
isPending: loading,
|
| 174 |
+
mutateAsync,
|
| 175 |
+
} = useMutation({
|
| 176 |
+
mutationKey: ['saveApiKey'],
|
| 177 |
+
mutationFn: async (params: IApiKeySavingParams) => {
|
| 178 |
+
const { data } = await userService.set_api_key(params);
|
| 179 |
+
if (data.retcode === 0) {
|
| 180 |
+
message.success(t('message.modified'));
|
| 181 |
+
queryClient.invalidateQueries({ queryKey: ['myLlmList'] });
|
| 182 |
+
queryClient.invalidateQueries({ queryKey: ['factoryList'] });
|
| 183 |
+
}
|
| 184 |
+
return data.retcode;
|
| 185 |
},
|
| 186 |
+
});
|
|
|
|
| 187 |
|
| 188 |
+
return { data, loading, saveApiKey: mutateAsync };
|
| 189 |
};
|
| 190 |
|
| 191 |
export interface ISystemModelSettingSavingParams {
|
|
|
|
| 198 |
}
|
| 199 |
|
| 200 |
export const useSaveTenantInfo = () => {
|
| 201 |
+
const { t } = useTranslation();
|
| 202 |
+
const {
|
| 203 |
+
data,
|
| 204 |
+
isPending: loading,
|
| 205 |
+
mutateAsync,
|
| 206 |
+
} = useMutation({
|
| 207 |
+
mutationKey: ['saveTenantInfo'],
|
| 208 |
+
mutationFn: async (params: ISystemModelSettingSavingParams) => {
|
| 209 |
+
const { data } = await userService.set_tenant_info(params);
|
| 210 |
+
if (data.retcode === 0) {
|
| 211 |
+
message.success(t('message.modified'));
|
| 212 |
+
}
|
| 213 |
+
return data.retcode;
|
| 214 |
},
|
| 215 |
+
});
|
|
|
|
| 216 |
|
| 217 |
+
return { data, loading, saveTenantInfo: mutateAsync };
|
| 218 |
};
|
| 219 |
|
| 220 |
export const useAddLlm = () => {
|
| 221 |
+
const queryClient = useQueryClient();
|
| 222 |
+
const { t } = useTranslation();
|
| 223 |
+
const {
|
| 224 |
+
data,
|
| 225 |
+
isPending: loading,
|
| 226 |
+
mutateAsync,
|
| 227 |
+
} = useMutation({
|
| 228 |
+
mutationKey: ['addLlm'],
|
| 229 |
+
mutationFn: async (params: IAddLlmRequestBody) => {
|
| 230 |
+
const { data } = await userService.add_llm(params);
|
| 231 |
+
if (data.retcode === 0) {
|
| 232 |
+
queryClient.invalidateQueries({ queryKey: ['myLlmList'] });
|
| 233 |
+
queryClient.invalidateQueries({ queryKey: ['factoryList'] });
|
| 234 |
+
message.success(t('message.modified'));
|
| 235 |
+
}
|
| 236 |
+
return data.retcode;
|
| 237 |
},
|
| 238 |
+
});
|
|
|
|
| 239 |
|
| 240 |
+
return { data, loading, addLlm: mutateAsync };
|
| 241 |
};
|
| 242 |
|
| 243 |
export const useDeleteLlm = () => {
|
| 244 |
+
const queryClient = useQueryClient();
|
| 245 |
+
const { t } = useTranslation();
|
| 246 |
+
const {
|
| 247 |
+
data,
|
| 248 |
+
isPending: loading,
|
| 249 |
+
mutateAsync,
|
| 250 |
+
} = useMutation({
|
| 251 |
+
mutationKey: ['deleteLlm'],
|
| 252 |
+
mutationFn: async (params: IDeleteLlmRequestBody) => {
|
| 253 |
+
const { data } = await userService.delete_llm(params);
|
| 254 |
+
if (data.retcode === 0) {
|
| 255 |
+
queryClient.invalidateQueries({ queryKey: ['myLlmList'] });
|
| 256 |
+
queryClient.invalidateQueries({ queryKey: ['factoryList'] });
|
| 257 |
+
message.success(t('message.deleted'));
|
| 258 |
+
}
|
| 259 |
+
return data.retcode;
|
| 260 |
},
|
| 261 |
+
});
|
|
|
|
| 262 |
|
| 263 |
+
return { data, loading, deleteLlm: mutateAsync };
|
| 264 |
};
|
web/src/hooks/logic-hooks.ts
CHANGED
|
@@ -22,7 +22,6 @@ import { useTranslation } from 'react-i18next';
|
|
| 22 |
import { useDispatch } from 'umi';
|
| 23 |
import { useSetModalState, useTranslate } from './common-hooks';
|
| 24 |
import { useSetDocumentParser } from './document-hooks';
|
| 25 |
-
import { useFetchLlmList } from './llm-hooks';
|
| 26 |
import { useSetPaginationParams } from './route-hook';
|
| 27 |
import { useOneNamespaceEffectsLoading } from './store-hooks';
|
| 28 |
import {
|
|
@@ -346,13 +345,3 @@ export const useFetchModelId = (visible: boolean) => {
|
|
| 346 |
|
| 347 |
return tenantInfo?.llm_id ?? '';
|
| 348 |
};
|
| 349 |
-
|
| 350 |
-
export const useFetchLlmModelOnVisible = (visible: boolean) => {
|
| 351 |
-
const fetchLlmList = useFetchLlmList();
|
| 352 |
-
|
| 353 |
-
useEffect(() => {
|
| 354 |
-
if (visible) {
|
| 355 |
-
fetchLlmList();
|
| 356 |
-
}
|
| 357 |
-
}, [fetchLlmList, visible]);
|
| 358 |
-
};
|
|
|
|
| 22 |
import { useDispatch } from 'umi';
|
| 23 |
import { useSetModalState, useTranslate } from './common-hooks';
|
| 24 |
import { useSetDocumentParser } from './document-hooks';
|
|
|
|
| 25 |
import { useSetPaginationParams } from './route-hook';
|
| 26 |
import { useOneNamespaceEffectsLoading } from './store-hooks';
|
| 27 |
import {
|
|
|
|
| 345 |
|
| 346 |
return tenantInfo?.llm_id ?? '';
|
| 347 |
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
web/src/interfaces/database/base.ts
CHANGED
|
@@ -4,3 +4,8 @@ export interface ResponseType<T = any> {
|
|
| 4 |
retmsg: string;
|
| 5 |
status: number;
|
| 6 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 4 |
retmsg: string;
|
| 5 |
status: number;
|
| 6 |
}
|
| 7 |
+
|
| 8 |
+
export interface ResponseGetType<T = any> {
|
| 9 |
+
data: T;
|
| 10 |
+
loading?: boolean;
|
| 11 |
+
}
|
web/src/pages/add-knowledge/components/knowledge-setting/hooks.ts
CHANGED
|
@@ -2,7 +2,7 @@ import {
|
|
| 2 |
useFetchKnowledgeBaseConfiguration,
|
| 3 |
useUpdateKnowledge,
|
| 4 |
} from '@/hooks/knowledge-hooks';
|
| 5 |
-
import {
|
| 6 |
import { useNavigateToDataset } from '@/hooks/route-hook';
|
| 7 |
import {
|
| 8 |
useFetchTenantInfo,
|
|
@@ -17,7 +17,6 @@ import { Form, UploadFile } from 'antd';
|
|
| 17 |
import { FormInstance } from 'antd/lib';
|
| 18 |
import pick from 'lodash/pick';
|
| 19 |
import { useCallback, useEffect } from 'react';
|
| 20 |
-
import { LlmModelType } from '../../constant';
|
| 21 |
|
| 22 |
export const useSubmitKnowledgeConfiguration = (form: FormInstance) => {
|
| 23 |
const { saveKnowledgeConfiguration, loading } = useUpdateKnowledge();
|
|
@@ -46,7 +45,6 @@ export const useFetchKnowledgeConfigurationOnMount = (form: FormInstance) => {
|
|
| 46 |
|
| 47 |
useFetchTenantInfo();
|
| 48 |
const { data: knowledgeDetails } = useFetchKnowledgeBaseConfiguration();
|
| 49 |
-
useFetchLlmList(LlmModelType.Embedding);
|
| 50 |
|
| 51 |
useEffect(() => {
|
| 52 |
const fileList: UploadFile[] = getUploadFileListFromBase64(
|
|
|
|
| 2 |
useFetchKnowledgeBaseConfiguration,
|
| 3 |
useUpdateKnowledge,
|
| 4 |
} from '@/hooks/knowledge-hooks';
|
| 5 |
+
import { useSelectLlmOptions } from '@/hooks/llm-hooks';
|
| 6 |
import { useNavigateToDataset } from '@/hooks/route-hook';
|
| 7 |
import {
|
| 8 |
useFetchTenantInfo,
|
|
|
|
| 17 |
import { FormInstance } from 'antd/lib';
|
| 18 |
import pick from 'lodash/pick';
|
| 19 |
import { useCallback, useEffect } from 'react';
|
|
|
|
| 20 |
|
| 21 |
export const useSubmitKnowledgeConfiguration = (form: FormInstance) => {
|
| 22 |
const { saveKnowledgeConfiguration, loading } = useUpdateKnowledge();
|
|
|
|
| 45 |
|
| 46 |
useFetchTenantInfo();
|
| 47 |
const { data: knowledgeDetails } = useFetchKnowledgeBaseConfiguration();
|
|
|
|
| 48 |
|
| 49 |
useEffect(() => {
|
| 50 |
const fileList: UploadFile[] = getUploadFileListFromBase64(
|
web/src/pages/add-knowledge/components/knowledge-testing/testing-control/index.tsx
CHANGED
|
@@ -1,12 +1,10 @@
|
|
|
|
|
| 1 |
import SimilaritySlider from '@/components/similarity-slider';
|
|
|
|
|
|
|
| 2 |
import { Button, Card, Divider, Flex, Form, Input } from 'antd';
|
| 3 |
import { FormInstance } from 'antd/lib';
|
| 4 |
|
| 5 |
-
import Rerank from '@/components/rerank';
|
| 6 |
-
import { useTranslate } from '@/hooks/common-hooks';
|
| 7 |
-
import { useFetchLlmList } from '@/hooks/llm-hooks';
|
| 8 |
-
import { useOneNamespaceEffectsLoading } from '@/hooks/store-hooks';
|
| 9 |
-
import { useEffect } from 'react';
|
| 10 |
import styles from './index.less';
|
| 11 |
|
| 12 |
type FieldType = {
|
|
@@ -26,11 +24,6 @@ const TestingControl = ({ form, handleTesting }: IProps) => {
|
|
| 26 |
'testDocumentChunk',
|
| 27 |
]);
|
| 28 |
const { t } = useTranslate('knowledgeDetails');
|
| 29 |
-
const fetchLlmList = useFetchLlmList();
|
| 30 |
-
|
| 31 |
-
useEffect(() => {
|
| 32 |
-
fetchLlmList();
|
| 33 |
-
}, [fetchLlmList]);
|
| 34 |
|
| 35 |
const buttonDisabled =
|
| 36 |
!question || (typeof question === 'string' && question.trim() === '');
|
|
|
|
| 1 |
+
import Rerank from '@/components/rerank';
|
| 2 |
import SimilaritySlider from '@/components/similarity-slider';
|
| 3 |
+
import { useTranslate } from '@/hooks/common-hooks';
|
| 4 |
+
import { useOneNamespaceEffectsLoading } from '@/hooks/store-hooks';
|
| 5 |
import { Button, Card, Divider, Flex, Form, Input } from 'antd';
|
| 6 |
import { FormInstance } from 'antd/lib';
|
| 7 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 8 |
import styles from './index.less';
|
| 9 |
|
| 10 |
type FieldType = {
|
|
|
|
| 24 |
'testDocumentChunk',
|
| 25 |
]);
|
| 26 |
const { t } = useTranslate('knowledgeDetails');
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 27 |
|
| 28 |
const buttonDisabled =
|
| 29 |
!question || (typeof question === 'string' && question.trim() === '');
|
web/src/pages/chat/chat-configuration-modal/index.tsx
CHANGED
|
@@ -4,7 +4,11 @@ import {
|
|
| 4 |
ModelVariableType,
|
| 5 |
settledModelVariableMap,
|
| 6 |
} from '@/constants/knowledge';
|
|
|
|
|
|
|
| 7 |
import { IDialog } from '@/interfaces/database/chat';
|
|
|
|
|
|
|
| 8 |
import { Divider, Flex, Form, Modal, Segmented, UploadFile } from 'antd';
|
| 9 |
import { SegmentedValue } from 'antd/es/segmented';
|
| 10 |
import camelCase from 'lodash/camelCase';
|
|
@@ -14,13 +18,6 @@ import AssistantSetting from './assistant-setting';
|
|
| 14 |
import ModelSetting from './model-setting';
|
| 15 |
import PromptEngine from './prompt-engine';
|
| 16 |
|
| 17 |
-
import { useTranslate } from '@/hooks/common-hooks';
|
| 18 |
-
import {
|
| 19 |
-
useFetchLlmModelOnVisible,
|
| 20 |
-
useFetchModelId,
|
| 21 |
-
} from '@/hooks/logic-hooks';
|
| 22 |
-
import { getBase64FromUploadFileList } from '@/utils/file-util';
|
| 23 |
-
import { removeUselessFieldsFromValues } from '@/utils/form';
|
| 24 |
import styles from './index.less';
|
| 25 |
|
| 26 |
const layout = {
|
|
@@ -99,10 +96,6 @@ const ChatConfigurationModal = ({
|
|
| 99 |
onOk(finalValues);
|
| 100 |
};
|
| 101 |
|
| 102 |
-
const handleCancel = () => {
|
| 103 |
-
hideModal();
|
| 104 |
-
};
|
| 105 |
-
|
| 106 |
const handleSegmentedChange = (val: SegmentedValue) => {
|
| 107 |
setValue(val as ConfigurationSegmented);
|
| 108 |
};
|
|
@@ -112,8 +105,6 @@ const ChatConfigurationModal = ({
|
|
| 112 |
form.resetFields();
|
| 113 |
};
|
| 114 |
|
| 115 |
-
useFetchLlmModelOnVisible(visible);
|
| 116 |
-
|
| 117 |
const title = (
|
| 118 |
<Flex gap={16}>
|
| 119 |
<ChatConfigurationAtom></ChatConfigurationAtom>
|
|
@@ -153,7 +144,7 @@ const ChatConfigurationModal = ({
|
|
| 153 |
width={688}
|
| 154 |
open={visible}
|
| 155 |
onOk={handleOk}
|
| 156 |
-
onCancel={
|
| 157 |
confirmLoading={loading}
|
| 158 |
destroyOnClose
|
| 159 |
afterClose={handleModalAfterClose}
|
|
|
|
| 4 |
ModelVariableType,
|
| 5 |
settledModelVariableMap,
|
| 6 |
} from '@/constants/knowledge';
|
| 7 |
+
import { useTranslate } from '@/hooks/common-hooks';
|
| 8 |
+
import { useFetchModelId } from '@/hooks/logic-hooks';
|
| 9 |
import { IDialog } from '@/interfaces/database/chat';
|
| 10 |
+
import { getBase64FromUploadFileList } from '@/utils/file-util';
|
| 11 |
+
import { removeUselessFieldsFromValues } from '@/utils/form';
|
| 12 |
import { Divider, Flex, Form, Modal, Segmented, UploadFile } from 'antd';
|
| 13 |
import { SegmentedValue } from 'antd/es/segmented';
|
| 14 |
import camelCase from 'lodash/camelCase';
|
|
|
|
| 18 |
import ModelSetting from './model-setting';
|
| 19 |
import PromptEngine from './prompt-engine';
|
| 20 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 21 |
import styles from './index.less';
|
| 22 |
|
| 23 |
const layout = {
|
|
|
|
| 96 |
onOk(finalValues);
|
| 97 |
};
|
| 98 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 99 |
const handleSegmentedChange = (val: SegmentedValue) => {
|
| 100 |
setValue(val as ConfigurationSegmented);
|
| 101 |
};
|
|
|
|
| 105 |
form.resetFields();
|
| 106 |
};
|
| 107 |
|
|
|
|
|
|
|
| 108 |
const title = (
|
| 109 |
<Flex gap={16}>
|
| 110 |
<ChatConfigurationAtom></ChatConfigurationAtom>
|
|
|
|
| 144 |
width={688}
|
| 145 |
open={visible}
|
| 146 |
onOk={handleOk}
|
| 147 |
+
onCancel={hideModal}
|
| 148 |
confirmLoading={loading}
|
| 149 |
destroyOnClose
|
| 150 |
afterClose={handleModalAfterClose}
|
web/src/pages/chat/index.tsx
CHANGED
|
@@ -353,15 +353,17 @@ const Chat = () => {
|
|
| 353 |
</Flex>
|
| 354 |
<Divider type={'vertical'} className={styles.divider}></Divider>
|
| 355 |
<ChatContainer></ChatContainer>
|
| 356 |
-
|
| 357 |
-
|
| 358 |
-
|
| 359 |
-
|
| 360 |
-
|
| 361 |
-
|
| 362 |
-
|
| 363 |
-
|
| 364 |
-
|
|
|
|
|
|
|
| 365 |
<RenameModal
|
| 366 |
visible={conversationRenameVisible}
|
| 367 |
hideModal={hideConversationRenameModal}
|
|
|
|
| 353 |
</Flex>
|
| 354 |
<Divider type={'vertical'} className={styles.divider}></Divider>
|
| 355 |
<ChatContainer></ChatContainer>
|
| 356 |
+
{dialogEditVisible && (
|
| 357 |
+
<ChatConfigurationModal
|
| 358 |
+
visible={dialogEditVisible}
|
| 359 |
+
initialDialog={initialDialog}
|
| 360 |
+
showModal={showDialogEditModal}
|
| 361 |
+
hideModal={hideDialogEditModal}
|
| 362 |
+
loading={dialogSettingLoading}
|
| 363 |
+
onOk={onDialogEditOk}
|
| 364 |
+
clearDialog={clearDialog}
|
| 365 |
+
></ChatConfigurationModal>
|
| 366 |
+
)}
|
| 367 |
<RenameModal
|
| 368 |
visible={conversationRenameVisible}
|
| 369 |
hideModal={hideConversationRenameModal}
|
web/src/pages/flow/hooks.ts
CHANGED
|
@@ -1,6 +1,5 @@
|
|
| 1 |
import { useSetModalState } from '@/hooks/common-hooks';
|
| 2 |
import { useFetchFlow, useResetFlow, useSetFlow } from '@/hooks/flow-hooks';
|
| 3 |
-
import { useFetchLlmList } from '@/hooks/llm-hooks';
|
| 4 |
import { IGraph } from '@/interfaces/database/flow';
|
| 5 |
import { useIsFetching } from '@tanstack/react-query';
|
| 6 |
import React, {
|
|
@@ -283,8 +282,6 @@ export const useFetchDataOnMount = () => {
|
|
| 283 |
|
| 284 |
useWatchGraphChange();
|
| 285 |
|
| 286 |
-
useFetchLlmList();
|
| 287 |
-
|
| 288 |
useEffect(() => {
|
| 289 |
refetch();
|
| 290 |
}, [refetch]);
|
|
|
|
| 1 |
import { useSetModalState } from '@/hooks/common-hooks';
|
| 2 |
import { useFetchFlow, useResetFlow, useSetFlow } from '@/hooks/flow-hooks';
|
|
|
|
| 3 |
import { IGraph } from '@/interfaces/database/flow';
|
| 4 |
import { useIsFetching } from '@tanstack/react-query';
|
| 5 |
import React, {
|
|
|
|
| 282 |
|
| 283 |
useWatchGraphChange();
|
| 284 |
|
|
|
|
|
|
|
| 285 |
useEffect(() => {
|
| 286 |
refetch();
|
| 287 |
}, [refetch]);
|
web/src/pages/user-setting/setting-model/hooks.ts
CHANGED
|
@@ -4,12 +4,10 @@ import {
|
|
| 4 |
ISystemModelSettingSavingParams,
|
| 5 |
useAddLlm,
|
| 6 |
useDeleteLlm,
|
| 7 |
-
useFetchLlmList,
|
| 8 |
useSaveApiKey,
|
| 9 |
useSaveTenantInfo,
|
| 10 |
useSelectLlmOptionsByModelType,
|
| 11 |
} from '@/hooks/llm-hooks';
|
| 12 |
-
import { useOneNamespaceEffectsLoading } from '@/hooks/store-hooks';
|
| 13 |
import {
|
| 14 |
useFetchTenantInfo,
|
| 15 |
useSelectTenantInfo,
|
|
@@ -24,7 +22,7 @@ export const useSubmitApiKey = () => {
|
|
| 24 |
const [savingParams, setSavingParams] = useState<SavingParamsState>(
|
| 25 |
{} as SavingParamsState,
|
| 26 |
);
|
| 27 |
-
const saveApiKey = useSaveApiKey();
|
| 28 |
const {
|
| 29 |
visible: apiKeyVisible,
|
| 30 |
hideModal: hideApiKeyModal,
|
|
@@ -53,10 +51,6 @@ export const useSubmitApiKey = () => {
|
|
| 53 |
[showApiKeyModal, setSavingParams],
|
| 54 |
);
|
| 55 |
|
| 56 |
-
const loading = useOneNamespaceEffectsLoading('settingModel', [
|
| 57 |
-
'set_api_key',
|
| 58 |
-
]);
|
| 59 |
-
|
| 60 |
return {
|
| 61 |
saveApiKeyLoading: loading,
|
| 62 |
initialApiKey: '',
|
|
@@ -70,10 +64,8 @@ export const useSubmitApiKey = () => {
|
|
| 70 |
|
| 71 |
export const useSubmitSystemModelSetting = () => {
|
| 72 |
const systemSetting = useSelectTenantInfo();
|
| 73 |
-
const
|
| 74 |
-
|
| 75 |
-
]);
|
| 76 |
-
const saveSystemModelSetting = useSaveTenantInfo();
|
| 77 |
const {
|
| 78 |
visible: systemSettingVisible,
|
| 79 |
hideModal: hideSystemSettingModal,
|
|
@@ -109,32 +101,20 @@ export const useSubmitSystemModelSetting = () => {
|
|
| 109 |
export const useFetchSystemModelSettingOnMount = (visible: boolean) => {
|
| 110 |
const systemSetting = useSelectTenantInfo();
|
| 111 |
const allOptions = useSelectLlmOptionsByModelType();
|
| 112 |
-
const fetchLlmList = useFetchLlmList();
|
| 113 |
const fetchTenantInfo = useFetchTenantInfo();
|
| 114 |
|
| 115 |
useEffect(() => {
|
| 116 |
if (visible) {
|
| 117 |
-
fetchLlmList();
|
| 118 |
fetchTenantInfo();
|
| 119 |
}
|
| 120 |
-
}, [
|
| 121 |
|
| 122 |
return { systemSetting, allOptions };
|
| 123 |
};
|
| 124 |
|
| 125 |
-
export const useSelectModelProvidersLoading = () => {
|
| 126 |
-
const loading = useOneNamespaceEffectsLoading('settingModel', [
|
| 127 |
-
'my_llm',
|
| 128 |
-
'factories_list',
|
| 129 |
-
]);
|
| 130 |
-
|
| 131 |
-
return loading;
|
| 132 |
-
};
|
| 133 |
-
|
| 134 |
export const useSubmitOllama = () => {
|
| 135 |
-
const loading = useOneNamespaceEffectsLoading('settingModel', ['add_llm']);
|
| 136 |
const [selectedLlmFactory, setSelectedLlmFactory] = useState<string>('');
|
| 137 |
-
const addLlm = useAddLlm();
|
| 138 |
const {
|
| 139 |
visible: llmAddingVisible,
|
| 140 |
hideModal: hideLlmAddingModal,
|
|
@@ -167,8 +147,7 @@ export const useSubmitOllama = () => {
|
|
| 167 |
};
|
| 168 |
|
| 169 |
export const useSubmitVolcEngine = () => {
|
| 170 |
-
const loading =
|
| 171 |
-
const addLlm = useAddLlm();
|
| 172 |
const {
|
| 173 |
visible: volcAddingVisible,
|
| 174 |
hideModal: hideVolcAddingModal,
|
|
@@ -195,8 +174,7 @@ export const useSubmitVolcEngine = () => {
|
|
| 195 |
};
|
| 196 |
|
| 197 |
export const useSubmitBedrock = () => {
|
| 198 |
-
const loading =
|
| 199 |
-
const addLlm = useAddLlm();
|
| 200 |
const {
|
| 201 |
visible: bedrockAddingVisible,
|
| 202 |
hideModal: hideBedrockAddingModal,
|
|
@@ -223,7 +201,7 @@ export const useSubmitBedrock = () => {
|
|
| 223 |
};
|
| 224 |
|
| 225 |
export const useHandleDeleteLlm = (llmFactory: string) => {
|
| 226 |
-
const deleteLlm = useDeleteLlm();
|
| 227 |
const showDeleteConfirm = useShowDeleteConfirm();
|
| 228 |
|
| 229 |
const handleDeleteLlm = (name: string) => () => {
|
|
|
|
| 4 |
ISystemModelSettingSavingParams,
|
| 5 |
useAddLlm,
|
| 6 |
useDeleteLlm,
|
|
|
|
| 7 |
useSaveApiKey,
|
| 8 |
useSaveTenantInfo,
|
| 9 |
useSelectLlmOptionsByModelType,
|
| 10 |
} from '@/hooks/llm-hooks';
|
|
|
|
| 11 |
import {
|
| 12 |
useFetchTenantInfo,
|
| 13 |
useSelectTenantInfo,
|
|
|
|
| 22 |
const [savingParams, setSavingParams] = useState<SavingParamsState>(
|
| 23 |
{} as SavingParamsState,
|
| 24 |
);
|
| 25 |
+
const { saveApiKey, loading } = useSaveApiKey();
|
| 26 |
const {
|
| 27 |
visible: apiKeyVisible,
|
| 28 |
hideModal: hideApiKeyModal,
|
|
|
|
| 51 |
[showApiKeyModal, setSavingParams],
|
| 52 |
);
|
| 53 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 54 |
return {
|
| 55 |
saveApiKeyLoading: loading,
|
| 56 |
initialApiKey: '',
|
|
|
|
| 64 |
|
| 65 |
export const useSubmitSystemModelSetting = () => {
|
| 66 |
const systemSetting = useSelectTenantInfo();
|
| 67 |
+
const { saveTenantInfo: saveSystemModelSetting, loading } =
|
| 68 |
+
useSaveTenantInfo();
|
|
|
|
|
|
|
| 69 |
const {
|
| 70 |
visible: systemSettingVisible,
|
| 71 |
hideModal: hideSystemSettingModal,
|
|
|
|
| 101 |
export const useFetchSystemModelSettingOnMount = (visible: boolean) => {
|
| 102 |
const systemSetting = useSelectTenantInfo();
|
| 103 |
const allOptions = useSelectLlmOptionsByModelType();
|
|
|
|
| 104 |
const fetchTenantInfo = useFetchTenantInfo();
|
| 105 |
|
| 106 |
useEffect(() => {
|
| 107 |
if (visible) {
|
|
|
|
| 108 |
fetchTenantInfo();
|
| 109 |
}
|
| 110 |
+
}, [fetchTenantInfo, visible]);
|
| 111 |
|
| 112 |
return { systemSetting, allOptions };
|
| 113 |
};
|
| 114 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 115 |
export const useSubmitOllama = () => {
|
|
|
|
| 116 |
const [selectedLlmFactory, setSelectedLlmFactory] = useState<string>('');
|
| 117 |
+
const { addLlm, loading } = useAddLlm();
|
| 118 |
const {
|
| 119 |
visible: llmAddingVisible,
|
| 120 |
hideModal: hideLlmAddingModal,
|
|
|
|
| 147 |
};
|
| 148 |
|
| 149 |
export const useSubmitVolcEngine = () => {
|
| 150 |
+
const { addLlm, loading } = useAddLlm();
|
|
|
|
| 151 |
const {
|
| 152 |
visible: volcAddingVisible,
|
| 153 |
hideModal: hideVolcAddingModal,
|
|
|
|
| 174 |
};
|
| 175 |
|
| 176 |
export const useSubmitBedrock = () => {
|
| 177 |
+
const { addLlm, loading } = useAddLlm();
|
|
|
|
| 178 |
const {
|
| 179 |
visible: bedrockAddingVisible,
|
| 180 |
hideModal: hideBedrockAddingModal,
|
|
|
|
| 201 |
};
|
| 202 |
|
| 203 |
export const useHandleDeleteLlm = (llmFactory: string) => {
|
| 204 |
+
const { deleteLlm } = useDeleteLlm();
|
| 205 |
const showDeleteConfirm = useShowDeleteConfirm();
|
| 206 |
|
| 207 |
const handleDeleteLlm = (name: string) => () => {
|
web/src/pages/user-setting/setting-model/index.tsx
CHANGED
|
@@ -1,11 +1,7 @@
|
|
| 1 |
import { ReactComponent as MoreModelIcon } from '@/assets/svg/more-model.svg';
|
| 2 |
import SvgIcon from '@/components/svg-icon';
|
| 3 |
import { useSetModalState, useTranslate } from '@/hooks/common-hooks';
|
| 4 |
-
import {
|
| 5 |
-
LlmItem,
|
| 6 |
-
useFetchLlmFactoryListOnMount,
|
| 7 |
-
useFetchMyLlmListOnMount,
|
| 8 |
-
} from '@/hooks/llm-hooks';
|
| 9 |
import {
|
| 10 |
CloseCircleOutlined,
|
| 11 |
SettingOutlined,
|
|
@@ -36,7 +32,6 @@ import BedrockModal from './bedrock-modal';
|
|
| 36 |
import { IconMap } from './constant';
|
| 37 |
import {
|
| 38 |
useHandleDeleteLlm,
|
| 39 |
-
useSelectModelProvidersLoading,
|
| 40 |
useSubmitApiKey,
|
| 41 |
useSubmitBedrock,
|
| 42 |
useSubmitOllama,
|
|
@@ -132,9 +127,7 @@ const ModelCard = ({ item, clickApiKey }: IModelCardProps) => {
|
|
| 132 |
};
|
| 133 |
|
| 134 |
const UserSettingModel = () => {
|
| 135 |
-
const factoryList =
|
| 136 |
-
const llmList = useFetchMyLlmListOnMount();
|
| 137 |
-
const loading = useSelectModelProvidersLoading();
|
| 138 |
const {
|
| 139 |
saveApiKeyLoading,
|
| 140 |
initialApiKey,
|
|
|
|
| 1 |
import { ReactComponent as MoreModelIcon } from '@/assets/svg/more-model.svg';
|
| 2 |
import SvgIcon from '@/components/svg-icon';
|
| 3 |
import { useSetModalState, useTranslate } from '@/hooks/common-hooks';
|
| 4 |
+
import { LlmItem, useSelectLlmList } from '@/hooks/llm-hooks';
|
|
|
|
|
|
|
|
|
|
|
|
|
| 5 |
import {
|
| 6 |
CloseCircleOutlined,
|
| 7 |
SettingOutlined,
|
|
|
|
| 32 |
import { IconMap } from './constant';
|
| 33 |
import {
|
| 34 |
useHandleDeleteLlm,
|
|
|
|
| 35 |
useSubmitApiKey,
|
| 36 |
useSubmitBedrock,
|
| 37 |
useSubmitOllama,
|
|
|
|
| 127 |
};
|
| 128 |
|
| 129 |
const UserSettingModel = () => {
|
| 130 |
+
const { factoryList, myLlmList: llmList, loading } = useSelectLlmList();
|
|
|
|
|
|
|
| 131 |
const {
|
| 132 |
saveApiKeyLoading,
|
| 133 |
initialApiKey,
|