Skip to content

Commit ecb8576

Browse files
author
Keivan Vosoughi
committed
Add Delete Model
1 parent 218b390 commit ecb8576

File tree

2 files changed

+78
-2
lines changed

2 files changed

+78
-2
lines changed

app/client/src/pages/Settings/SettingsPage.tsx

Lines changed: 70 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,19 @@
1-
import { Button, Col, Flex, Layout, Row, Table } from "antd";
1+
import { Button, Col, Flex, Layout, Modal, notification, Row, Table, Tooltip, Tooltip } from "antd";
22
import { Content } from "antd/es/layout/layout";
33
import styled from "styled-components";
4-
import { useModelProviders } from "./hooks";
4+
import { deleteModelProvider, useModelProviders } from "./hooks";
55
import get from "lodash/get";
66
import { sortItemsByKey } from "../../utils/sortutils";
77
import Paragraph from "antd/es/typography/Paragraph";
88
import StyledTitle from "../Evaluator/StyledTitle";
99
import Toolbar from "./Toolbar";
1010
import AddModelProviderButton, { ModelProviderType } from "./AddModelProviderButton";
1111
import DateTime from "../../components/DateTime/DateTime";
12+
import {
13+
EditOutlined,
14+
DeleteOutlined
15+
} from '@ant-design/icons';
16+
import { useMutation } from "@tanstack/react-query";
1217

1318

1419

@@ -65,12 +70,42 @@ const StyledParagraph = styled(Paragraph)`
6570
color: #5a656d;
6671
`;
6772

73+
const StyledButton = styled(Button)`
74+
margin-left: 8px;
75+
`;
76+
6877
const SettingsPage: React.FC = () => {
6978
const filteredModelsReq = useModelProviders();
7079
console.log('filteredModelsReq', filteredModelsReq);
7180
const customModels = get(filteredModelsReq, 'data.endpoints', []);
7281

82+
const mutation = useMutation({
83+
mutationFn: deleteModelProvider
84+
});
7385

86+
const onDelete = (model: CustomModel) => {
87+
Modal.confirm({
88+
content: (
89+
<span>{`Are you sure you want to delete the model ${model}`}</span>
90+
),
91+
onOk: async () => {
92+
try {
93+
mutation.mutate({
94+
model_id: model.model_id,
95+
provider_type: model.provider_type
96+
})
97+
} catch (error) {
98+
notification.error({
99+
message: "Error",
100+
description: error instanceof Error ? error.message : String(error),
101+
});
102+
}
103+
},
104+
title: 'Confirm'
105+
});
106+
};
107+
108+
const onEdit = () => {}
74109

75110
const modelProvidersColumns = [{
76111
key: 'display_name',
@@ -117,6 +152,39 @@ const SettingsPage: React.FC = () => {
117152
width: 300,
118153
sorter: sortItemsByKey('endpoint_url'),
119154
render: (endpoint_url: string) => <StyledParagraph style={{ width: 200, marginBottom: 0 }} ellipsis={{ rows: 1 }}>{endpoint_url}</StyledParagraph>
155+
}, {
156+
title: 'Actions',
157+
width: 100,
158+
render: (model: CustomModel) => {
159+
console.log('model', model);
160+
return (
161+
<Flex>
162+
<Tooltip title="Edit">
163+
<Button
164+
type="link"
165+
key={`${model.endpoint_id}-delete`}
166+
onClick={() => onDelete(model)}
167+
data-event-category="User Action"
168+
data-event="Delete"
169+
>
170+
<DeleteOutlined />
171+
</Button>
172+
</Tooltip>
173+
<Tooltip title="Edit">
174+
<StyledButton
175+
type="link"
176+
key={`${model.endpoint_id}-deploy`}
177+
onClick={onEdit}
178+
data-event-category="User Action"
179+
data-event="Edit"
180+
>
181+
<EditOutlined />
182+
</StyledButton>
183+
</Tooltip>
184+
</Flex>
185+
);
186+
187+
}
120188
}];
121189

122190

app/client/src/pages/Settings/hooks.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,14 @@ const fetchFilteredModels = async () => {
1212
};
1313

1414

15+
export const deleteModelProvider = async ({ model_id, provider_type }) => {
16+
const model_filtered_resp = await fetch(`/custom_model_endpoints/${model_id}/${provider_type}`, {
17+
method: 'DELETE'
18+
});
19+
return await model_filtered_resp.json();
20+
}
21+
22+
1523
export const useModelProviders = () => {
1624

1725
const { data, isLoading, isError, refetch } = useQuery(

0 commit comments

Comments
 (0)