diff --git a/litellm/proxy/proxy_server.py b/litellm/proxy/proxy_server.py index cf9414c41..3d0f9b4d1 100644 --- a/litellm/proxy/proxy_server.py +++ b/litellm/proxy/proxy_server.py @@ -7004,6 +7004,7 @@ async def add_new_model( ).decode("utf-8") await prisma_client.db.litellm_proxymodeltable.create( data={ + "model_id": model_params.model_info.id, "model_name": model_params.model_name, "litellm_params": model_params.litellm_params.model_dump_json(exclude_none=True), # type: ignore "model_info": model_params.model_info.model_dump_json( # type: ignore @@ -7278,9 +7279,19 @@ async def delete_model(model_info: ModelInfoDelete): - store keys separately """ # encrypt litellm params # - await prisma_client.db.litellm_proxymodeltable.delete( + result = await prisma_client.db.litellm_proxymodeltable.delete( where={"model_id": model_info.id} ) + + if result is None: + raise HTTPException( + status_code=400, + detail={ + "error": f"Model with id={model_info.id} not found in db" + }, + ) + + return {"message": f"Model: {result.model_id} deleted successfully"} else: raise HTTPException( status_code=500, @@ -7288,7 +7299,7 @@ async def delete_model(model_info: ModelInfoDelete): "error": "Set `'STORE_MODEL_IN_DB='True'` in your env to enable this feature." }, ) - return {"message": "Model deleted successfully"} + except Exception as e: if isinstance(e, HTTPException): diff --git a/ui/litellm-dashboard/src/components/delete_model_button.tsx b/ui/litellm-dashboard/src/components/delete_model_button.tsx new file mode 100644 index 000000000..ee23cdb1b --- /dev/null +++ b/ui/litellm-dashboard/src/components/delete_model_button.tsx @@ -0,0 +1,71 @@ +"use client"; + +import React, { useState } from "react"; +import { Grid, Col, Icon } from "@tremor/react"; +import { Title } from "@tremor/react"; +import { + Modal, + message, +} from "antd"; +import { modelDeleteCall } from "./networking"; +import { TrashIcon } from "@heroicons/react/outline"; + +interface DeleteModelProps { + modelID: string; + accessToken: string; +} + +const DeleteModelButton: React.FC = ({ + modelID, + accessToken, +}) => { + const [isModalVisible, setIsModalVisible] = useState(false); + + const handleDelete = async () => { + try { + message.info("Making API Call"); + setIsModalVisible(true); + const response = await modelDeleteCall(accessToken, modelID); + + console.log("model delete Response:", response); + message.success(`Model ${modelID} deleted successfully`); + setIsModalVisible(false); + } catch (error) { + console.error("Error deleting the model:", error); + } + }; + + return ( +
+ setIsModalVisible(true)} + icon={TrashIcon} + size="sm" + /> + + setIsModalVisible(false)} + > + + + Delete Model + +

+ Are you sure you want to delete this model? This action is irreversible. +

+ + +

+ Model ID: {modelID} +

+ +
+
+
+ ); +}; + +export default DeleteModelButton; \ No newline at end of file diff --git a/ui/litellm-dashboard/src/components/model_dashboard.tsx b/ui/litellm-dashboard/src/components/model_dashboard.tsx index 018dd7e20..a083fdf84 100644 --- a/ui/litellm-dashboard/src/components/model_dashboard.tsx +++ b/ui/litellm-dashboard/src/components/model_dashboard.tsx @@ -35,6 +35,7 @@ import RequestAccess from "./request_model_access"; import { Typography } from "antd"; import TextArea from "antd/es/input/TextArea"; import { InformationCircleIcon, PencilAltIcon, PencilIcon, StatusOnlineIcon, TrashIcon } from "@heroicons/react/outline"; +import DeleteModelButton from "./delete_model_button"; const { Title: Title2, Link } = Typography; import { UploadOutlined } from '@ant-design/icons'; import type { UploadProps } from 'antd'; @@ -261,11 +262,6 @@ const ModelDashboard: React.FC = ({ ); } - const handleDelete = async (model_id: string) => { - await modelDeleteCall(accessToken, model_id) - }; - - const setProviderModelsFn = (provider: string) => { console.log(`received provider string: ${provider}`) const providerKey = Object.keys(Providers).find(key => (Providers as {[index: string]: any})[key] === provider); @@ -480,7 +476,9 @@ const ModelDashboard: React.FC = ({ {model.input_cost} {model.output_cost} {model.max_tokens} - handleDelete(model.model_info.id)}/> + + + ))}