diff --git a/web/src/hooks/llm-hooks.ts b/web/src/hooks/llm-hooks.ts index e667bc7d977..534b896ddd2 100644 --- a/web/src/hooks/llm-hooks.ts +++ b/web/src/hooks/llm-hooks.ts @@ -278,3 +278,26 @@ export const useDeleteLlm = () => { return { data, loading, deleteLlm: mutateAsync }; }; + +export const useDeleteFactory = () => { + const queryClient = useQueryClient(); + const { t } = useTranslation(); + const { + data, + isPending: loading, + mutateAsync, + } = useMutation({ + mutationKey: ['deleteFactory'], + mutationFn: async (params: IDeleteLlmRequestBody) => { + const { data } = await userService.deleteFactory(params); + if (data.retcode === 0) { + queryClient.invalidateQueries({ queryKey: ['myLlmList'] }); + queryClient.invalidateQueries({ queryKey: ['factoryList'] }); + message.success(t('message.deleted')); + } + return data.retcode; + }, + }); + + return { data, loading, deleteFactory: mutateAsync }; +}; diff --git a/web/src/interfaces/request/llm.ts b/web/src/interfaces/request/llm.ts index 2db66484e35..309fd45d0b3 100644 --- a/web/src/interfaces/request/llm.ts +++ b/web/src/interfaces/request/llm.ts @@ -8,5 +8,5 @@ export interface IAddLlmRequestBody { export interface IDeleteLlmRequestBody { llm_factory: string; // Ollama - llm_name: string; + llm_name?: string; } diff --git a/web/src/pages/user-setting/setting-model/hooks.ts b/web/src/pages/user-setting/setting-model/hooks.ts index f076a27d158..a53159f15e6 100644 --- a/web/src/pages/user-setting/setting-model/hooks.ts +++ b/web/src/pages/user-setting/setting-model/hooks.ts @@ -3,6 +3,7 @@ import { IApiKeySavingParams, ISystemModelSettingSavingParams, useAddLlm, + useDeleteFactory, useDeleteLlm, useSaveApiKey, useSaveTenantInfo, @@ -366,3 +367,18 @@ export const useHandleDeleteLlm = (llmFactory: string) => { return { handleDeleteLlm }; }; + +export const useHandleDeleteFactory = (llmFactory: string) => { + const { deleteFactory } = useDeleteFactory(); + const showDeleteConfirm = useShowDeleteConfirm(); + + const handleDeleteFactory = () => { + showDeleteConfirm({ + onOk: async () => { + deleteFactory({ llm_factory: llmFactory }); + }, + }); + }; + + return { handleDeleteFactory }; +}; diff --git a/web/src/pages/user-setting/setting-model/index.tsx b/web/src/pages/user-setting/setting-model/index.tsx index e2b5c85efbf..14287d78561 100644 --- a/web/src/pages/user-setting/setting-model/index.tsx +++ b/web/src/pages/user-setting/setting-model/index.tsx @@ -34,6 +34,7 @@ import { IconMap } from './constant'; import FishAudioModal from './fish-audio-modal'; import GoogleModal from './google-modal'; import { + useHandleDeleteFactory, useHandleDeleteLlm, useSubmitApiKey, useSubmitBedrock, @@ -75,6 +76,7 @@ const ModelCard = ({ item, clickApiKey }: IModelCardProps) => { const { visible, switchVisible } = useSetModalState(); const { t } = useTranslate('setting'); const { handleDeleteLlm } = useHandleDeleteLlm(item.name); + const { handleDeleteFactory } = useHandleDeleteFactory(item.name); const handleApiKeyClick = () => { clickApiKey(item.name); @@ -118,6 +120,9 @@ const ModelCard = ({ item, clickApiKey }: IModelCardProps) => { + diff --git a/web/src/services/user-service.ts b/web/src/services/user-service.ts index 322c6b2fec6..f68f2d30631 100644 --- a/web/src/services/user-service.ts +++ b/web/src/services/user-service.ts @@ -16,6 +16,7 @@ const { set_tenant_info, add_llm, delete_llm, + deleteFactory, getSystemStatus, getSystemVersion, } = api; @@ -81,6 +82,10 @@ const methods = { url: getSystemVersion, method: 'get', }, + deleteFactory: { + url: deleteFactory, + method: 'post', + }, } as const; const userService = registerServer(methods, request); diff --git a/web/src/utils/api.ts b/web/src/utils/api.ts index df1cc42d2d8..94e1a584025 100644 --- a/web/src/utils/api.ts +++ b/web/src/utils/api.ts @@ -19,6 +19,7 @@ export default { set_api_key: `${api_host}/llm/set_api_key`, add_llm: `${api_host}/llm/add_llm`, delete_llm: `${api_host}/llm/delete_llm`, + deleteFactory: `${api_host}/llm/delete_factory`, // knowledge base kb_list: `${api_host}/kb/list`,