chore: remove source in the form
This commit is contained in:
@@ -47,6 +47,7 @@ interface DataFormProps {
|
|||||||
onSourceChange?: (value: string) => void;
|
onSourceChange?: (value: string) => void;
|
||||||
onOk: (values: FormData) => void;
|
onOk: (values: FormData) => void;
|
||||||
onBackendChange?: (value: string) => void;
|
onBackendChange?: (value: string) => void;
|
||||||
|
fields?: string[];
|
||||||
}
|
}
|
||||||
|
|
||||||
const SEARCH_SOURCE = [
|
const SEARCH_SOURCE = [
|
||||||
@@ -64,6 +65,7 @@ const DataForm: React.FC<DataFormProps> = forwardRef((props, ref) => {
|
|||||||
byBuiltIn,
|
byBuiltIn,
|
||||||
sizeOptions = [],
|
sizeOptions = [],
|
||||||
quantizationOptions = [],
|
quantizationOptions = [],
|
||||||
|
fields = ['source'],
|
||||||
onSourceChange,
|
onSourceChange,
|
||||||
onOk
|
onOk
|
||||||
} = props;
|
} = props;
|
||||||
@@ -508,7 +510,7 @@ const DataForm: React.FC<DataFormProps> = forwardRef((props, ref) => {
|
|||||||
required
|
required
|
||||||
></SealInput.Input>
|
></SealInput.Input>
|
||||||
</Form.Item>
|
</Form.Item>
|
||||||
{
|
{fields.includes('source') && (
|
||||||
<Form.Item<FormData>
|
<Form.Item<FormData>
|
||||||
name="source"
|
name="source"
|
||||||
rules={[
|
rules={[
|
||||||
@@ -535,7 +537,7 @@ const DataForm: React.FC<DataFormProps> = forwardRef((props, ref) => {
|
|||||||
></SealSelect>
|
></SealSelect>
|
||||||
}
|
}
|
||||||
</Form.Item>
|
</Form.Item>
|
||||||
}
|
)}
|
||||||
|
|
||||||
{renderFieldsBySource}
|
{renderFieldsBySource}
|
||||||
<Form.Item name="backend" rules={[{ required: true }]}>
|
<Form.Item name="backend" rules={[{ required: true }]}>
|
||||||
|
|||||||
@@ -69,6 +69,7 @@ const AddModal: React.FC<AddModalProps> = (props) => {
|
|||||||
const sourceGroupMap = useRef<any>({});
|
const sourceGroupMap = useRef<any>({});
|
||||||
const axiosToken = useRef<any>(null);
|
const axiosToken = useRef<any>(null);
|
||||||
const selectSpecRef = useRef<CatalogSpec>({} as CatalogSpec);
|
const selectSpecRef = useRef<CatalogSpec>({} as CatalogSpec);
|
||||||
|
const specListRef = useRef<any[]>([]);
|
||||||
|
|
||||||
const handleSumit = () => {
|
const handleSumit = () => {
|
||||||
form.current?.submit?.();
|
form.current?.submit?.();
|
||||||
@@ -165,14 +166,17 @@ const AddModal: React.FC<AddModalProps> = (props) => {
|
|||||||
'size'
|
'size'
|
||||||
);
|
);
|
||||||
|
|
||||||
const sizeList = _.keys(sizeGroup).map((size: string) => {
|
const sizeList = _.keys(sizeGroup)
|
||||||
return {
|
.map((size: string) => {
|
||||||
label: `${size}B`,
|
return {
|
||||||
value: _.toNumber(size)
|
label: `${size}B`,
|
||||||
};
|
value: _.toNumber(size)
|
||||||
});
|
};
|
||||||
setSizeOptions(sizeList);
|
})
|
||||||
return sizeList;
|
.filter((item: any) => item.value);
|
||||||
|
const result = _.sortBy(sizeList, 'value');
|
||||||
|
setSizeOptions(result);
|
||||||
|
return result;
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleSetQuantizationOptions = (data: {
|
const handleSetQuantizationOptions = (data: {
|
||||||
@@ -225,6 +229,33 @@ const AddModal: React.FC<AddModalProps> = (props) => {
|
|||||||
initFormDataBySource(defaultSpec);
|
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) => {
|
const handleBackendChange = (backend: string) => {
|
||||||
if (backend === backendOptionsMap.vllm) {
|
if (backend === backendOptionsMap.vllm) {
|
||||||
setIsGGUF(false);
|
setIsGGUF(false);
|
||||||
@@ -237,23 +268,22 @@ const AddModal: React.FC<AddModalProps> = (props) => {
|
|||||||
source: form.current.getFieldValue('source'),
|
source: form.current.getFieldValue('source'),
|
||||||
backend: backend
|
backend: backend
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const size = checkSize(sizeList);
|
||||||
|
|
||||||
const quantizaList = handleSetQuantizationOptions({
|
const quantizaList = handleSetQuantizationOptions({
|
||||||
source: form.current.getFieldValue('source'),
|
source: form.current.getFieldValue('source'),
|
||||||
size: _.get(sizeList, '0.value', 0),
|
size: size,
|
||||||
backend: backend
|
backend: backend
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const quantization = checkQuantization(quantizaList);
|
||||||
|
|
||||||
const data = getModelSpec({
|
const data = getModelSpec({
|
||||||
source: form.current.getFieldValue('source'),
|
source: form.current.getFieldValue('source'),
|
||||||
backend: backend,
|
backend: backend,
|
||||||
size: _.get(sizeList, '0.value', 0),
|
size: size,
|
||||||
quantization:
|
quantization: quantization
|
||||||
_.find(quantizaList, (item: { label: string; value: string }) =>
|
|
||||||
getDefaultQuant({
|
|
||||||
category: _.get(current, 'categories.0', ''),
|
|
||||||
quantOption: item.value
|
|
||||||
})
|
|
||||||
)?.value || _.get(quantizaList, '0.value', '')
|
|
||||||
});
|
});
|
||||||
|
|
||||||
form.current.setFieldsValue({
|
form.current.setFieldsValue({
|
||||||
@@ -288,6 +318,7 @@ const AddModal: React.FC<AddModalProps> = (props) => {
|
|||||||
});
|
});
|
||||||
}) || _.get(groupList, `${source}.0`, {});
|
}) || _.get(groupList, `${source}.0`, {});
|
||||||
|
|
||||||
|
selectSpecRef.current = defaultSpec;
|
||||||
setSourceList(sources);
|
setSourceList(sources);
|
||||||
handleSetBackendOptions(source);
|
handleSetBackendOptions(source);
|
||||||
handleSetSizeOptions({
|
handleSetSizeOptions({
|
||||||
@@ -335,17 +366,13 @@ const AddModal: React.FC<AddModalProps> = (props) => {
|
|||||||
size: val
|
size: val
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const quantization = checkQuantization(list);
|
||||||
|
|
||||||
const data = getModelSpec({
|
const data = getModelSpec({
|
||||||
source: form.current.getFieldValue('source'),
|
source: form.current.getFieldValue('source'),
|
||||||
backend: form.current.getFieldValue('backend'),
|
backend: form.current.getFieldValue('backend'),
|
||||||
size: val,
|
size: val,
|
||||||
quantization:
|
quantization: quantization
|
||||||
_.find(list, (item: { label: string; value: string }) =>
|
|
||||||
getDefaultQuant({
|
|
||||||
category: _.get(current, 'categories.0', ''),
|
|
||||||
quantOption: item.value
|
|
||||||
})
|
|
||||||
)?.value || _.get(list, '0.value', '')
|
|
||||||
});
|
});
|
||||||
|
|
||||||
// set form data
|
// set form data
|
||||||
@@ -357,7 +384,8 @@ const AddModal: React.FC<AddModalProps> = (props) => {
|
|||||||
const handleOk = (values: FormData) => {
|
const handleOk = (values: FormData) => {
|
||||||
onOk({
|
onOk({
|
||||||
...values,
|
...values,
|
||||||
...getModelFile(selectSpecRef.current)
|
...getModelFile(selectSpecRef.current),
|
||||||
|
..._.omit(selectSpecRef.current, ['name'])
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -428,6 +456,7 @@ const AddModal: React.FC<AddModalProps> = (props) => {
|
|||||||
>
|
>
|
||||||
<>
|
<>
|
||||||
<DataForm
|
<DataForm
|
||||||
|
fields={[]}
|
||||||
source={source}
|
source={source}
|
||||||
action={action}
|
action={action}
|
||||||
selectedModel={{}}
|
selectedModel={{}}
|
||||||
|
|||||||
Reference in New Issue
Block a user