-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTeamLLMProviderDetail.tsx
399 lines (368 loc) · 11 KB
/
TeamLLMProviderDetail.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
import React, { useState, useEffect } from 'react';
import {
Card,
Typography,
Button,
Space,
Table,
Tag,
Modal,
message,
Popconfirm,
Tooltip,
Descriptions,
Divider
} from 'antd';
import {
EditOutlined,
DeleteOutlined,
PlusOutlined,
CheckCircleOutlined,
StopOutlined,
StarOutlined,
StarFilled,
ArrowLeftOutlined
} from '@ant-design/icons';
import { LLMModel, LLMProvider } from '../../models/llm';
import LLMModelForm from './LLMModelForm';
import LLMProviderForm from './LLMProviderForm';
import {
fetchTeamProviderModels,
createTeamProviderModel,
updateTeamProviderModel,
deleteTeamProviderModel,
updateTeamLLMProvider
} from '../../services/teamService';
const { Title, Text } = Typography;
interface TeamLLMProviderDetailProps {
teamId: string;
provider: LLMProvider;
canManageModels: boolean;
onBackToList: () => void;
onProviderUpdated: () => void;
}
const TeamLLMProviderDetail: React.FC<TeamLLMProviderDetailProps> = ({
teamId,
provider,
canManageModels,
onBackToList,
onProviderUpdated
}) => {
const [models, setModels] = useState<LLMModel[]>([]);
const [loading, setLoading] = useState(false);
const [isAddModalVisible, setIsAddModalVisible] = useState(false);
const [isEditModalVisible, setIsEditModalVisible] = useState(false);
const [isEditProviderModalVisible, setIsEditProviderModalVisible] = useState(false);
const [editingModel, setEditingModel] = useState<LLMModel | null>(null);
const [actionLoading, setActionLoading] = useState(false);
const fetchModels = React.useCallback(async () => {
if (!provider?.id) return;
if (!teamId) return;
setLoading(true);
try {
const data = await fetchTeamProviderModels(teamId, provider.id);
if (data) setModels(data);
} catch (error: unknown) {
console.error('Error fetching models:', error);
message.error('Failed to load models');
} finally {
setLoading(false);
}
}, [teamId, provider?.id]);
useEffect(() => {
fetchModels();
}, [fetchModels]);
const handleAddModel = async (values: any) => {
if (!provider?.id) return;
setActionLoading(true);
try {
await createTeamProviderModel(teamId, provider.id, values);
message.success('Model added successfully');
setIsAddModalVisible(false);
fetchModels();
} catch (error: unknown) {
console.error('Error adding model:', error);
message.error('Failed to add model');
} finally {
setActionLoading(false);
}
};
const handleEditModel = async (values: any) => {
if (!provider?.id || !editingModel?.id) return;
setActionLoading(true);
try {
await updateTeamProviderModel(teamId, provider.id, editingModel.id, values);
message.success('Model updated successfully');
setIsEditModalVisible(false);
setEditingModel(null);
fetchModels();
} catch (error: unknown) {
console.error('Error updating model:', error);
message.error('Failed to update model');
} finally {
setActionLoading(false);
}
};
const handleDeleteModel = async (modelId: string) => {
if (!provider?.id) return;
try {
await deleteTeamProviderModel(teamId, provider.id, modelId);
message.success('Model deleted successfully');
fetchModels();
} catch (error: unknown) {
console.error('Error deleting model:', error);
message.error('Failed to delete model');
}
};
const handleEditProvider = async (values: any) => {
if (!provider?.id) return;
setActionLoading(true);
try {
await updateTeamLLMProvider(teamId, provider.id, values);
message.success('Provider updated successfully');
setIsEditProviderModalVisible(false);
onProviderUpdated(); // Call the callback to refresh provider data
} catch (error: unknown) {
console.error('Error updating provider:', error);
message.error('Failed to update provider');
} finally {
setActionLoading(false);
}
};
const getModelTypeTag = (type: string) => {
let color = '';
let label = type;
switch (type) {
case 'chat':
color = 'green';
label = 'Chat';
break;
case 'text':
color = 'blue';
label = 'Text';
break;
case 'embedding':
color = 'purple';
label = 'Embedding';
break;
case 'image':
color = 'orange';
label = 'Image';
break;
default:
color = 'default';
break;
}
return <Tag color={color}>{label}</Tag>;
};
const columns = [
{
title: 'Model',
key: 'name',
render: (record: LLMModel) => (
<Space direction="vertical" size={0}>
<Space>
{record.isDefault && (
<Tooltip title="Default Model for this type">
<StarFilled style={{ color: '#faad14' }} />
</Tooltip>
)}
<Typography.Text strong>
{record.displayName || record.name}
</Typography.Text>
</Space>
<Typography.Text type="secondary" style={{ fontSize: '12px' }}>
{record.name}
</Typography.Text>
</Space>
),
},
{
title: 'Type',
dataIndex: 'modelType',
key: 'modelType',
render: getModelTypeTag,
},
{
title: 'Context Window',
dataIndex: 'contextWindow',
key: 'contextWindow',
render: (value: number) => value ? `${value.toLocaleString()} tokens` : '-',
},
{
title: 'Status',
key: 'status',
render: (record: LLMModel) => (
<Tag color={record.isActive ? 'success' : 'error'} icon={record.isActive ? <CheckCircleOutlined /> : <StopOutlined />}>
{record.isActive ? 'Active' : 'Inactive'}
</Tag>
),
},
{
title: 'Actions',
key: 'actions',
render: (record: LLMModel) => (
canManageModels ? (
<Space size="small">
<Tooltip title="Edit Model">
<Button
type="text"
icon={<EditOutlined />}
onClick={() => {
setEditingModel(record);
setIsEditModalVisible(true);
}}
/>
</Tooltip>
{!record.isDefault && (
<Tooltip title="Set as Default for this type">
<Button
type="text"
icon={<StarOutlined />}
onClick={() => handleSetDefault(record)}
disabled={actionLoading}
/>
</Tooltip>
)}
<Popconfirm
title="Delete this model?"
description="This action cannot be undone."
onConfirm={() => handleDeleteModel(record.id)}
okText="Delete"
cancelText="Cancel"
okButtonProps={{ danger: true }}
>
<Button type="text" danger icon={<DeleteOutlined />} />
</Popconfirm>
</Space>
) : (
<Text type="secondary">-</Text>
)
),
},
];
const handleSetDefault = async (model: LLMModel) => {
setActionLoading(true);
try {
await updateTeamProviderModel(teamId, provider.id, model.id, {
isDefault: true
});
message.success('Default model updated');
fetchModels();
} catch (error: unknown) {
console.error('Error setting default model:', error);
message.error('Failed to update default model');
} finally {
setActionLoading(false);
}
};
return (
<div>
<Card>
<div style={{ display: 'flex', justifyContent: 'space-between', alignItems: 'center', marginBottom: 16 }}>
<Space>
<Button icon={<ArrowLeftOutlined />} onClick={onBackToList}>
Back to providers
</Button>
<Title level={4} style={{ margin: 0 }}>
Provider: {provider.name}
</Title>
</Space>
{canManageModels && (
<Button
type="primary"
icon={<EditOutlined />}
onClick={() => setIsEditProviderModalVisible(true)}
>
Edit Provider
</Button>
)}
</div>
<Descriptions bordered column={2}>
<Descriptions.Item label="Name">{provider.name}</Descriptions.Item>
<Descriptions.Item label="Type">{provider.providerType}</Descriptions.Item>
<Descriptions.Item label="Endpoint URL">{provider.endpointUrl}</Descriptions.Item>
<Descriptions.Item label="Status">
{provider.isActive ? (
<Tag icon={<CheckCircleOutlined />} color="success">Active</Tag>
) : (
<Tag icon={<StopOutlined />} color="error">Inactive</Tag>
)}
</Descriptions.Item>
<Descriptions.Item label="Description" span={2}>{provider.description || 'No description'}</Descriptions.Item>
</Descriptions>
<Divider />
<div style={{ display: 'flex', justifyContent: 'space-between', alignItems: 'center', marginBottom: 16 }}>
<Title level={4}>Models</Title>
{canManageModels && (
<Button
type="primary"
icon={<PlusOutlined />}
onClick={() => setIsAddModalVisible(true)}
>
Add Model
</Button>
)}
</div>
<Table
dataSource={models}
columns={columns}
rowKey="id"
loading={loading}
pagination={false}
/>
</Card>
{/* Add Model Modal */}
<Modal
title="Add Model"
open={isAddModalVisible}
onCancel={() => setIsAddModalVisible(false)}
footer={null}
width={700}
>
<LLMModelForm
onSubmit={handleAddModel}
isLoading={actionLoading}
providerId={provider?.id}
providerType={provider?.providerType}
teamContext={teamId}
/>
</Modal>
{/* Edit Model Modal */}
{editingModel && (
<Modal
title="Edit Model"
open={isEditModalVisible}
onCancel={() => setIsEditModalVisible(false)}
footer={null}
width={700}
>
<LLMModelForm
initialValues={editingModel}
onSubmit={handleEditModel}
isLoading={actionLoading}
providerId={provider?.id}
providerType={provider?.providerType}
teamContext={teamId}
/>
</Modal>
)}
{/* Edit Provider Modal */}
<Modal
title="Edit Provider"
open={isEditProviderModalVisible}
onCancel={() => setIsEditProviderModalVisible(false)}
footer={null}
width={700}
>
<LLMProviderForm
initialValues={provider}
onSubmit={handleEditProvider}
isLoading={actionLoading}
teamContext={teamId}
/>
</Modal>
</div>
);
};
export default TeamLLMProviderDetail;