MCPcopy Create free account
hub / github.com/experdot/pointer / LLMConfigForm

Function LLMConfigForm

src/renderer/src/components/settings/LLMSettings.tsx:42–240  ·  view source on GitHub ↗
({ open, config, onSave, onCancel }: LLMConfigFormProps)

Source from the content-addressed store, hash-verified

40}
41
42function LLMConfigForm({ open, config, onSave, onCancel }: LLMConfigFormProps) {
43 const [form] = Form.useForm()
44 const [loading, setLoading] = useState(false)
45 const [modelLoading, setModelLoading] = useState(false)
46 const [models, setModels] = useState<string[]>([])
47 const { message } = App.useApp()
48 const { settings } = useSettingsStore()
49
50 // 当 config 变化时,更新表单值
51 useEffect(() => {
52 if (open) {
53 if (config) {
54 form.setFieldsValue(config)
55 } else {
56 form.resetFields()
57 }
58 setModels([])
59 }
60 }, [open, config, form])
61
62 const handleSave = async () => {
63 try {
64 setLoading(true)
65 const values = await form.validateFields()
66
67 const newConfig: LLMConfig = {
68 id: config?.id || uuidv4(),
69 name: values.name,
70 apiHost: values.apiHost,
71 apiKey: values.apiKey,
72 modelName: values.modelName,
73 createdAt: config?.createdAt || Date.now(),
74 modelConfigId: values.modelConfigId
75 }
76
77 onSave(newConfig)
78 form.resetFields()
79 } catch (error) {
80 message.error('请检查输入内容')
81 } finally {
82 setLoading(false)
83 }
84 }
85
86 const fetchModels = async () => {
87 try {
88 const apiHost = form.getFieldValue('apiHost')
89 const apiKey = form.getFieldValue('apiKey')
90
91 if (!apiHost || !apiKey) {
92 message.warning('请先输入 API Host 和 API Key')
93 return
94 }
95
96 setModelLoading(true)
97 const result = await window.api.ai.getModels({
98 apiHost,
99 apiKey,

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected