Skip to content

Commit

Permalink
feat: Delete Model Provider #2376 (#2565)
Browse files Browse the repository at this point in the history
### What problem does this PR solve?

feat: Delete Model Provider #2376

### Type of change

- [ ] Bug Fix (non-breaking change which fixes an issue)
- [x] New Feature (non-breaking change which adds functionality)
  • Loading branch information
cike8899 authored Sep 24, 2024
1 parent 91dbce3 commit 9251fb3
Show file tree
Hide file tree
Showing 6 changed files with 51 additions and 1 deletion.
23 changes: 23 additions & 0 deletions web/src/hooks/llm-hooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 };
};
2 changes: 1 addition & 1 deletion web/src/interfaces/request/llm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@ export interface IAddLlmRequestBody {

export interface IDeleteLlmRequestBody {
llm_factory: string; // Ollama
llm_name: string;
llm_name?: string;
}
16 changes: 16 additions & 0 deletions web/src/pages/user-setting/setting-model/hooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import {
IApiKeySavingParams,
ISystemModelSettingSavingParams,
useAddLlm,
useDeleteFactory,
useDeleteLlm,
useSaveApiKey,
useSaveTenantInfo,
Expand Down Expand Up @@ -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 };
};
5 changes: 5 additions & 0 deletions web/src/pages/user-setting/setting-model/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import { IconMap } from './constant';
import FishAudioModal from './fish-audio-modal';
import GoogleModal from './google-modal';
import {
useHandleDeleteFactory,
useHandleDeleteLlm,
useSubmitApiKey,
useSubmitBedrock,
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -118,6 +120,9 @@ const ModelCard = ({ item, clickApiKey }: IModelCardProps) => {
<MoreModelIcon />
</Flex>
</Button>
<Button type={'text'} onClick={handleDeleteFactory}>
<CloseCircleOutlined style={{ color: '#D92D20' }} />
</Button>
</Space>
</Col>
</Row>
Expand Down
5 changes: 5 additions & 0 deletions web/src/services/user-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ const {
set_tenant_info,
add_llm,
delete_llm,
deleteFactory,
getSystemStatus,
getSystemVersion,
} = api;
Expand Down Expand Up @@ -81,6 +82,10 @@ const methods = {
url: getSystemVersion,
method: 'get',
},
deleteFactory: {
url: deleteFactory,
method: 'post',
},
} as const;

const userService = registerServer<keyof typeof methods>(methods, request);
Expand Down
1 change: 1 addition & 0 deletions web/src/utils/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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`,
Expand Down

0 comments on commit 9251fb3

Please sign in to comment.