import { IModalManagerChildrenProps } from '@/components/modal-manager'; import { Form, FormControl, FormField, FormItem, FormLabel, FormMessage, } from '@/components/ui/form'; import { Input } from '@/components/ui/input'; import { Modal } from '@/components/ui/modal/modal'; import { LLMFactory } from '@/constants/llm'; import { useTranslate } from '@/hooks/common-hooks'; import { KeyboardEventHandler, useCallback, useEffect } from 'react'; import { useForm } from 'react-hook-form'; import { ApiKeyPostBody } from '../../../interface'; import { LLMHeader } from '../../components/llm-header'; interface IProps extends Omit { loading: boolean; initialValue: string; llmFactory: string; editMode?: boolean; onOk: (postBody: ApiKeyPostBody) => void; showModal?(): void; } type FieldType = { api_key?: string; base_url?: string; group_id?: string; }; const modelsWithBaseUrl = [ LLMFactory.OpenAI, LLMFactory.AzureOpenAI, LLMFactory.TongYiQianWen, LLMFactory.MiniMax, ]; const ApiKeyModal = ({ visible, hideModal, llmFactory, loading, initialValue, editMode = false, onOk, }: IProps) => { const form = useForm(); const { t } = useTranslate('setting'); const handleOk = useCallback(async () => { await form.handleSubmit((values) => onOk(values))(); }, [form, onOk]); const handleKeyDown: KeyboardEventHandler = useCallback( async (e) => { if (e.key === 'Enter') { await handleOk(); } }, [handleOk], ); useEffect(() => { if (visible) { form.setValue('api_key', initialValue); } }, [initialValue, form, visible]); return ( } open={visible} onOpenChange={(open) => !open && hideModal()} onOk={handleOk} onCancel={hideModal} confirmLoading={loading} okText={t('save')} cancelText={t('cancel')} className="!w-[600px]" >
( {t('apiKey')} )} /> {modelsWithBaseUrl.some((x) => x === llmFactory) && ( ( {t('baseUrl')} )} /> )} {llmFactory?.toLowerCase() === 'Anthropic'.toLowerCase() && ( ( {t('baseUrl')} )} /> )} {llmFactory?.toLowerCase() === 'Minimax'.toLowerCase() && ( ( Group ID )} /> )}
); }; export default ApiKeyModal;