Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Delete Model Provider #2376 #2565

Merged
merged 1 commit into from
Sep 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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