fix: categories value error

This commit is contained in:
jialin
2025-04-02 17:55:10 +08:00
parent 89a6d6a4c1
commit d3e58c85cf
9 changed files with 46 additions and 44 deletions
+13 -9
View File
@@ -13,6 +13,7 @@ import {
ModelscopeTaskMap,
backendOptionsMap,
backendTipsList,
excludeFields,
modelSourceMap,
modelTaskMap,
sourceOptions
@@ -23,7 +24,7 @@ import { FormData, SourceType } from '../config/types';
import CatalogFrom from '../forms/catalog';
import HuggingFaceForm from '../forms/hugging-face';
import LocalPathForm from '../forms/local-path';
import OllamaForm from '../forms/ollama-library';
import OllamaForm from '../forms/ollama_library';
import AdvanceConfig from './advance-config';
interface DataFormProps {
@@ -190,19 +191,17 @@ const DataForm: React.FC<DataFormProps> = forwardRef((props, ref) => {
const handleOk = async (formdata: FormData) => {
let data = _.cloneDeep(formdata);
if (data.categories) {
data.categories = [data.categories];
} else {
data.categories = [];
}
data.categories = Array.isArray(data.categories)
? data.categories
: data.categories
? [data.categories]
: [];
const gpuSelector = generateGPUIds(data);
const allValues = {
..._.omit(data, ['scheduleType']),
...gpuSelector
};
console.log('allValues--------', allValues);
onOk(allValues);
};
@@ -211,7 +210,10 @@ const DataForm: React.FC<DataFormProps> = forwardRef((props, ref) => {
};
const handleOnValuesChange = async (changedValues: any, allValues: any) => {
console.log('changeValues--------', changedValues);
const fieldName = Object.keys(changedValues)[0];
if (excludeFields.includes(fieldName)) {
return;
}
onValuesChange?.(changedValues, allValues);
};
@@ -251,6 +253,7 @@ const DataForm: React.FC<DataFormProps> = forwardRef((props, ref) => {
style={{ padding: '16px 24px' }}
clearOnDestroy={true}
onValuesChange={handleOnValuesChange}
scrollToFirstError={true}
initialValues={{
replicas: 1,
source: props.source,
@@ -258,6 +261,7 @@ const DataForm: React.FC<DataFormProps> = forwardRef((props, ref) => {
cpu_offloading: true,
scheduleType: 'auto',
categories: null,
restart_on_error: true,
distributed_inference_across_workers: true,
...initialValues
}}
@@ -419,7 +419,10 @@ const AddModal: React.FC<AddModalProps> = (props) => {
};
const handleOk = async (values: FormData) => {
const data = generateSubmitData(values);
const data = {
..._.omit(selectSpecRef.current, ['name']),
...values
};
onOk(data);
};
@@ -14,6 +14,7 @@ import React, { useEffect, useMemo, useRef } from 'react';
import {
backendOptionsMap,
backendTipsList,
excludeFields,
getSourceRepoConfigValue,
localPathTipsList,
modelSourceMap,
@@ -319,6 +320,10 @@ const UpdateModal: React.FC<AddModalProps> = (props) => {
};
const onValuesChange = (changedValues: any, allValues: any) => {
const fieldName = Object.keys(changedValues)[0];
if (excludeFields.includes(fieldName)) {
return;
}
handleOnValuesChange({
changedValues,
allValues,
@@ -423,6 +428,7 @@ const UpdateModal: React.FC<AddModalProps> = (props) => {
form={form}
onFinish={handleOk}
onValuesChange={onValuesChange}
scrollToFirstError={true}
preserve={false}
clearOnDestroy={true}
initialValues={{
+3 -1
View File
@@ -456,5 +456,7 @@ export const excludeFields = [
'source',
'quantization',
'size',
'restart_on_error'
'restart_on_error',
'worker_selector',
'backend_parameters'
];
+2 -2
View File
@@ -22,7 +22,7 @@ const LocalPathForm: React.FC = () => {
const { modelFileOptions, byBuiltIn } = formCtx;
const { getRuleMessage } = useAppUtils();
const intl = useIntl();
const localPathCache = useRef<string>(form.getFieldValue('local_path'));
const localPathCache = useRef<string>(form.getFieldValue('local_path') || '');
if (![modelSourceMap.local_path_value].includes(source) || byBuiltIn) {
return null;
@@ -30,7 +30,7 @@ const LocalPathForm: React.FC = () => {
const handleLocalPathBlur = (e: any) => {
const value = e.target.value;
if (value === localPathCache.current && value) {
if (value === localPathCache.current || !value) {
return;
}
const isEndwithGGUF = _.endsWith(value, '.gguf');
+14 -25
View File
@@ -8,7 +8,6 @@ import { useEffect, useRef, useState } from 'react';
import { evaluationsModelSpec, queryGPUList } from '../apis';
import {
backendOptionsMap,
excludeFields,
getSourceRepoConfigValue,
modelSourceMap,
setSourceRepoConfigValue
@@ -157,7 +156,10 @@ export const useGenerateModelFileOptions = () => {
labels: worker.labels,
parent: true,
children: list
.filter((item) => item.worker_id === worker.id)
.filter(
(item) =>
item.worker_id === worker.id && !!item.resolved_paths?.length
)
.map((item) => {
const resolved_paths =
Array.isArray(item.resolved_paths) && item.resolved_paths.length
@@ -384,34 +386,21 @@ export const useCheckCompatibility = () => {
source: string;
}) => {
const { changedValues, allValues, source } = params;
const keys = Object.keys(changedValues);
const isExcludeField = keys.some((key) => excludeFields.includes(key));
const hasValue = keys.every((key) => {
return !!changedValues[key];
const data = getSourceRepoConfigValue(source, allValues);
const gpuSelector = generateGPUIds(data.values);
const currentRequestId = updateRequestId();
const evalutionData = await handleEvaluate({
...data.values,
...gpuSelector
});
if (
!isExcludeField &&
hasValue &&
!_.has(changedValues, 'backend') &&
!_.has(changedValues, 'local_path')
) {
const data = getSourceRepoConfigValue(source, allValues);
const gpuSelector = generateGPUIds(data.values);
const currentRequestId = updateRequestId();
const evalutionData = await handleEvaluate({
...data.values,
...gpuSelector
});
if (currentRequestId === requestIdRef.current) {
handleShowCompatibleAlert?.(evalutionData);
}
if (currentRequestId === requestIdRef.current) {
handleShowCompatibleAlert?.(evalutionData);
}
};
const debounceHandleValuesChange = _.debounce(handleOnValuesChange, 300);
const debounceHandleValuesChange = _.debounce(handleOnValuesChange, 500);
const cancelEvaluate = () => {
checkTokenRef.current?.cancel();