From 60d25a18fb4a5521cd5acdfa0b267c4016661e04 Mon Sep 17 00:00:00 2001 From: jialin Date: Wed, 8 Jan 2025 12:34:16 +0800 Subject: [PATCH] chore: remove source in the form --- src/pages/llmodels/components/data-form.tsx | 6 +- .../components/deploy-builtin-modal.tsx | 79 +++++++++++++------ 2 files changed, 58 insertions(+), 27 deletions(-) diff --git a/src/pages/llmodels/components/data-form.tsx b/src/pages/llmodels/components/data-form.tsx index 1649d658..26a1f81e 100644 --- a/src/pages/llmodels/components/data-form.tsx +++ b/src/pages/llmodels/components/data-form.tsx @@ -47,6 +47,7 @@ interface DataFormProps { onSourceChange?: (value: string) => void; onOk: (values: FormData) => void; onBackendChange?: (value: string) => void; + fields?: string[]; } const SEARCH_SOURCE = [ @@ -64,6 +65,7 @@ const DataForm: React.FC = forwardRef((props, ref) => { byBuiltIn, sizeOptions = [], quantizationOptions = [], + fields = ['source'], onSourceChange, onOk } = props; @@ -508,7 +510,7 @@ const DataForm: React.FC = forwardRef((props, ref) => { required > - { + {fields.includes('source') && ( name="source" rules={[ @@ -535,7 +537,7 @@ const DataForm: React.FC = forwardRef((props, ref) => { > } - } + )} {renderFieldsBySource} diff --git a/src/pages/llmodels/components/deploy-builtin-modal.tsx b/src/pages/llmodels/components/deploy-builtin-modal.tsx index ee7d76e3..bed131fe 100644 --- a/src/pages/llmodels/components/deploy-builtin-modal.tsx +++ b/src/pages/llmodels/components/deploy-builtin-modal.tsx @@ -69,6 +69,7 @@ const AddModal: React.FC = (props) => { const sourceGroupMap = useRef({}); const axiosToken = useRef(null); const selectSpecRef = useRef({} as CatalogSpec); + const specListRef = useRef([]); const handleSumit = () => { form.current?.submit?.(); @@ -165,14 +166,17 @@ const AddModal: React.FC = (props) => { 'size' ); - const sizeList = _.keys(sizeGroup).map((size: string) => { - return { - label: `${size}B`, - value: _.toNumber(size) - }; - }); - setSizeOptions(sizeList); - return sizeList; + const sizeList = _.keys(sizeGroup) + .map((size: string) => { + return { + label: `${size}B`, + value: _.toNumber(size) + }; + }) + .filter((item: any) => item.value); + const result = _.sortBy(sizeList, 'value'); + setSizeOptions(result); + return result; }; const handleSetQuantizationOptions = (data: { @@ -225,6 +229,33 @@ const AddModal: React.FC = (props) => { initFormDataBySource(defaultSpec); }; + const checkSize = (list: any[]) => { + return ( + _.find( + list, + (item: { label: string; value: string }) => + item.value === form.current.getFieldValue('size') + )?.value || _.get(list, '0.value', 0) + ); + }; + + const checkQuantization = (list: any[]) => { + return ( + _.find( + list, + (item: { label: string; value: string }) => + item.value === form.current.getFieldValue('quantization') + )?.value || + _.find(list, (item: { label: string; value: string }) => + getDefaultQuant({ + category: _.get(current, 'categories.0', ''), + quantOption: item.value + }) + )?.value || + _.get(list, '0.value', '') + ); + }; + const handleBackendChange = (backend: string) => { if (backend === backendOptionsMap.vllm) { setIsGGUF(false); @@ -237,23 +268,22 @@ const AddModal: React.FC = (props) => { source: form.current.getFieldValue('source'), backend: backend }); + + const size = checkSize(sizeList); + const quantizaList = handleSetQuantizationOptions({ source: form.current.getFieldValue('source'), - size: _.get(sizeList, '0.value', 0), + size: size, backend: backend }); + const quantization = checkQuantization(quantizaList); + const data = getModelSpec({ source: form.current.getFieldValue('source'), backend: backend, - size: _.get(sizeList, '0.value', 0), - quantization: - _.find(quantizaList, (item: { label: string; value: string }) => - getDefaultQuant({ - category: _.get(current, 'categories.0', ''), - quantOption: item.value - }) - )?.value || _.get(quantizaList, '0.value', '') + size: size, + quantization: quantization }); form.current.setFieldsValue({ @@ -288,6 +318,7 @@ const AddModal: React.FC = (props) => { }); }) || _.get(groupList, `${source}.0`, {}); + selectSpecRef.current = defaultSpec; setSourceList(sources); handleSetBackendOptions(source); handleSetSizeOptions({ @@ -335,17 +366,13 @@ const AddModal: React.FC = (props) => { size: val }); + const quantization = checkQuantization(list); + const data = getModelSpec({ source: form.current.getFieldValue('source'), backend: form.current.getFieldValue('backend'), size: val, - quantization: - _.find(list, (item: { label: string; value: string }) => - getDefaultQuant({ - category: _.get(current, 'categories.0', ''), - quantOption: item.value - }) - )?.value || _.get(list, '0.value', '') + quantization: quantization }); // set form data @@ -357,7 +384,8 @@ const AddModal: React.FC = (props) => { const handleOk = (values: FormData) => { onOk({ ...values, - ...getModelFile(selectSpecRef.current) + ...getModelFile(selectSpecRef.current), + ..._.omit(selectSpecRef.current, ['name']) }); }; @@ -428,6 +456,7 @@ const AddModal: React.FC = (props) => { > <>