-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLLMModelForm.tsx
210 lines (191 loc) · 6.13 KB
/
LLMModelForm.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
import React, { useState, useEffect } from 'react';
import {
Form,
Input,
Select,
Switch,
Button,
Card,
Typography,
message,
InputNumber,
Spin
} from 'antd';
import { SaveOutlined } from '@ant-design/icons';
import {
CreateLLMModelRequest,
UpdateLLMModelRequest,
LLMModelType,
LLMModel,
LLMProvider
} from '../../models/llm';
import { fetchAllLLMProviders } from '../../services/llmService';
import { fetchTeamLLMProviders } from '../../services/teamService';
const { Title, Text } = Typography;
const { Option } = Select;
const { TextArea } = Input;
interface LLMModelFormProps {
initialValues?: Partial<LLMModel>;
providerType?: string;
providerId?: string;
onSubmit: (values: CreateLLMModelRequest | UpdateLLMModelRequest) => Promise<void>;
isLoading?: boolean;
teamContext?: string; // Optional team ID for team-specific providers
}
const LLMModelForm: React.FC<LLMModelFormProps> = ({
initialValues,
providerId,
onSubmit,
isLoading = false,
teamContext
}) => {
const [form] = Form.useForm();
const isEdit = !!initialValues?.id;
const [providers, setProviders] = useState<LLMProvider[]>([]);
const [loadingProviders, setLoadingProviders] = useState(false);
useEffect(() => {
const fetchProviders = async () => {
setLoadingProviders(true);
try {
let providersData;
if (teamContext) {
// If we have a team context, we should fetch team-specific providers
// This requires importing the team service and using fetchTeamLLMProviders
providersData = await fetchTeamLLMProviders(teamContext);
} else {
// Fetch all available providers
providersData = await fetchAllLLMProviders();
}
setProviders(providersData || []);
} catch (error: unknown) {
console.error('Failed to fetch providers:', error);
message.error('Failed to load LLM providers');
} finally {
setLoadingProviders(false);
}
};
fetchProviders();
}, [teamContext]);
const modelTypes: { label: string, value: LLMModelType }[] = [
{ label: 'Chat Completion', value: 'chat' },
{ label: 'Text Completion', value: 'text' },
{ label: 'Embedding', value: 'embedding' },
{ label: 'Image Generation', value: 'image' }
];
const handleFinish = async (values: any) => {
try {
// If providerId is passed as prop, use it
if (providerId && !values.providerId) {
values.providerId = providerId;
}
await onSubmit(values);
message.success(`Model ${isEdit ? 'updated' : 'created'} successfully!`);
} catch (error: unknown) {
console.error('Model form error:', error);
message.error(`Failed to ${isEdit ? 'update' : 'create'} model`);
}
};
return (
<Card>
<Title level={4}>{isEdit ? 'Edit Model' : 'Add New LLM Model'}</Title>
<Form
form={form}
layout="vertical"
initialValues={{
isActive: true,
isDefault: false,
modelType: 'chat',
...initialValues,
// If providerId is supplied as prop, override initialValues
...(providerId ? { providerId } : {})
}}
onFinish={handleFinish}
>
<Form.Item
name="name"
label="Model Name"
rules={[{ required: true, message: 'Please enter model name' }]}
tooltip="The actual model identifier used in API calls (e.g., gpt-4, claude-2)"
>
<Input placeholder="e.g., gpt-4, gpt-3.5-turbo, claude-2" />
</Form.Item>
<Form.Item
name="displayName"
label="Display Name"
tooltip="A user-friendly name to display in the UI"
>
<Input placeholder="e.g., GPT-4, Claude 2" />
</Form.Item>
<Form.Item
name="description"
label="Description"
>
<TextArea rows={2} placeholder="Optional description of this model's capabilities" />
</Form.Item>
<Form.Item
name="modelType"
label="Model Type"
rules={[{ required: true, message: 'Please select model type' }]}
>
<Select placeholder="Select model type">
{modelTypes.map(type => (
<Option key={type.value} value={type.value}>
{type.label}
</Option>
))}
</Select>
</Form.Item>
{!providerId && (
<Form.Item
name="providerId"
label="Provider"
rules={[{ required: true, message: 'Please select a provider' }]}
>
<Select
placeholder="Select provider"
loading={loadingProviders}
notFoundContent={loadingProviders ? <Spin size="small" /> : 'No providers found'}
>
{providers.map(provider => (
<Option key={provider.id} value={provider.id}>
{provider.name}
</Option>
))}
</Select>
</Form.Item>
)}
<Form.Item
name="contextWindow"
label="Context Window Size"
tooltip="Maximum number of tokens this model can process"
>
<InputNumber
min={0}
step={1024}
placeholder="e.g., 8192, 16384"
style={{ width: '100%' }}
/>
</Form.Item>
<Form.Item name="isActive" valuePropName="checked">
<Switch checkedChildren="Active" unCheckedChildren="Inactive" />
<Text style={{ marginLeft: 8 }}>Enable this model</Text>
</Form.Item>
<Form.Item name="isDefault" valuePropName="checked">
<Switch checkedChildren="Default" unCheckedChildren="Not Default" />
<Text style={{ marginLeft: 8 }}>Set as default model for this type</Text>
</Form.Item>
<Form.Item>
<Button
type="primary"
htmlType="submit"
loading={isLoading}
icon={<SaveOutlined />}
>
{isEdit ? 'Update Model' : 'Add Model'}
</Button>
</Form.Item>
</Form>
</Card>
);
};
export default LLMModelForm;