import { IModalManagerChildrenProps } from '@/components/modal-manager'; import { Form, Input, Modal } from 'antd'; import { useEffect } from 'react'; interface IProps extends Omit { loading: boolean; initialValue: string; llmFactory: string; onOk: (name: string, baseUrl: string) => void; showModal?(): void; } type FieldType = { api_key?: string; base_url?: string; }; const ApiKeyModal = ({ visible, hideModal, llmFactory, loading, initialValue, onOk, }: IProps) => { const [form] = Form.useForm(); const handleOk = async () => { const ret = await form.validateFields(); return onOk(ret.api_key, ret.base_url); }; const handleCancel = () => { hideModal(); }; const onFinish = (values: any) => { console.log('Success:', values); }; const onFinishFailed = (errorInfo: any) => { console.log('Failed:', errorInfo); }; useEffect(() => { form.setFieldValue('api_key', initialValue); }, [initialValue, form]); return (
label="Api-Key" name="api_key" tooltip="The API key can be obtained by registering the corresponding LLM supplier." rules={[{ required: true, message: 'Please input api key!' }]} > {llmFactory === 'OpenAI' && ( label="Base-Url" name="base_url" tooltip="If your API key is from OpenAI, just ignore it. Any other intermediate providers will give this base url with the API key." > )}
); }; export default ApiKeyModal;