import IconFont from '@/components/icon-font'; import SealAutoComplete from '@/components/seal-form/auto-complete'; import SealInput from '@/components/seal-form/seal-input'; import SealSelect from '@/components/seal-form/seal-select'; import useAppUtils from '@/hooks/use-app-utils'; import { ModelFileFormData as FormData } from '@/pages/resources/config/types'; import { useIntl } from '@umijs/max'; import { Form, Typography } from 'antd'; import React, { forwardRef, useImperativeHandle, useMemo } from 'react'; import { modelSourceMap, ollamaModelOptions, sourceOptions } from '../config'; interface TargetFormProps { ref?: any; workersList: Global.BaseOption[]; source: string; onOk: (values: any) => void; } const TargetForm: React.FC = forwardRef((props, ref) => { const { onOk, source, workersList } = props; const { getRuleMessage } = useAppUtils(); const intl = useIntl(); const [form] = Form.useForm(); useImperativeHandle(ref, () => ({ form })); const handleOk = (values: any) => { onOk(values); }; const renderLocalPathFields = () => { return ( <> name="local_path" key="local_path" rules={[ { required: true, message: getRuleMessage('input', 'models.form.filePath') } ]} > ); }; const renderOllamaModelFields = () => { return ( <> name="ollama_library_model_name" key="ollama_library_model_name" rules={[ { required: true, message: getRuleMessage('input', 'models.table.name') } ]} > {intl.formatMessage({ id: 'models.form.ollamalink' })} } label={intl.formatMessage({ id: 'model.form.ollama.model' })} placeholder={intl.formatMessage({ id: 'model.form.ollamaholder' })} required > ); }; const renderFieldsBySource = useMemo(() => { if (props.source === modelSourceMap.ollama_library_value) { return renderOllamaModelFields(); } if (props.source === modelSourceMap.local_path_value) { return renderLocalPathFields(); } return null; }, [props.source, intl]); return (
name="source" rules={[ { required: true, message: getRuleMessage('select', 'models.form.source') } ]} > { } {renderFieldsBySource} { } {source !== modelSourceMap.local_path_value && ( name="local_dir" rules={[ { required: true, message: getRuleMessage('input', 'resources.modelfiles.form.path') } ]} > )} ); }); export default TargetForm;