fix: edit gpu_selector failed

This commit is contained in:
jialin
2025-09-17 19:53:40 +08:00
parent 4d9dec8511
commit bf400547e1
17 changed files with 296 additions and 544 deletions
+13 -14
View File
@@ -1,31 +1,30 @@
import { PageActionType } from '@/config/types';
import React from 'react';
import { DeployFormKey } from './types';
interface FormContextProps {
isGGUF?: boolean;
byBuiltIn?: boolean;
formKey: DeployFormKey;
source?: string;
pageAction: PageActionType;
sizeOptions?: Global.BaseOption<number>[];
quantizationOptions?: Global.BaseOption<string>[];
gpuOptions?: any[];
onSizeChange?: (val: number) => void;
onQuantizationChange?: (val: string) => void;
onValuesChange?: (changedValues: any, allValues: any) => void;
onBackendChange?: (backend: string) => void;
}
interface FormInnerContextProps {
onBackendChange?: (backend: string) => void;
onValuesChange?: (changedValues: any, allValues: any) => void;
gpuOptions?: any[];
interface CatalogFormContextProps {
sizeOptions: Global.BaseOption<number>[];
quantizationOptions: Global.BaseOption<string>[];
onSizeChange: (val: number) => void;
onQuantizationChange: (val: string) => void;
}
export const FormContext = React.createContext<FormContextProps>(
{} as FormContextProps
);
export const FormInnerContext = React.createContext<FormInnerContextProps>(
{} as FormInnerContextProps
export const CatalogFormContext = React.createContext<CatalogFormContextProps>(
{} as CatalogFormContextProps
);
export const useFormContext = () => {
@@ -36,11 +35,11 @@ export const useFormContext = () => {
return context;
};
export const useFormInnerContext = () => {
const context = React.useContext(FormInnerContext);
export const useCatalogFormContext = () => {
const context = React.useContext(CatalogFormContext);
if (!context) {
throw new Error(
'useFormInnerContext must be used within a FormInnerProvider'
'useCatalogFormContext must be used within a CatalogFormProvider'
);
}
return context;
+6 -54
View File
@@ -1,7 +1,7 @@
import { StatusMaps } from '@/config';
import { EditOutlined } from '@ant-design/icons';
import _ from 'lodash';
import { backendOptionsMap } from './backend-parameters';
import { DeployFormKey } from './types';
export const backendTipsList = [
{
@@ -277,59 +277,6 @@ export const modelCategories = [
...categoryOptions
];
export const sourceRepoConfig = {
[modelSourceMap.huggingface_value]: {
repo_id: 'huggingface_repo_id',
file_name: 'huggingface_filename'
},
[modelSourceMap.modelscope_value]: {
repo_id: 'model_scope_model_id',
file_name: 'model_scope_file_path'
}
};
export const getSourceRepoConfigValue = (
source: string,
data: any
): {
values: typeof data;
} => {
const config: Record<string, any> = sourceRepoConfig[source] || {};
const result: Record<string, any> = {};
const omits: string[] = [];
Object.keys(config)?.forEach((key: string) => {
if (config[key]) {
result[config[key]] = data[key];
omits.push(key);
}
});
return {
values: { ...result, ..._.omit(data, omits) }
};
};
export const setSourceRepoConfigValue = (
source: string,
data: any
): {
values: Record<string, any>;
} => {
const config: Record<string, any> = sourceRepoConfig[source] || {};
const result: Record<string, any> = {};
const omits: string[] = [];
Object.keys(config)?.forEach((key: string) => {
if (config[key]) {
result[key] = data[config[key]];
omits.push(config[key]);
}
});
return {
values: { ...result, ..._.omit(data, omits) }
};
};
export const getbackendParameters = (data: any) => {
const backendParameters = data.backend_parameters || {};
const result: string[] = [];
@@ -487,3 +434,8 @@ export const scheduleTypeTips = [
tips: 'models.form.scheduletype.manual.tips'
}
];
export const deployFormKeyMap: Record<string, DeployFormKey> = {
deployment: 'deployment',
catalog: 'catalog'
};
+3 -1
View File
@@ -30,6 +30,8 @@ export interface ListItem {
worker_selector?: object;
}
export type DeployFormKey = 'deployment' | 'catalog';
export type SourceType =
| 'huggingface'
| 'model_scope'
@@ -45,7 +47,7 @@ export interface FormData {
categories?: string[];
backend_parameters?: string[];
backend_version?: string;
source: string;
source: SourceType;
repo_id: string;
file_name: string;
huggingface_repo_id: string;
+33
View File
@@ -0,0 +1,33 @@
import _ from 'lodash';
import { backendOptionsMap } from '../config/backend-parameters';
export const generateGPUSelector = (data: any, gpuOptions: any[]) => {
const gpu_ids = _.get(data, 'gpu_selector.gpu_ids', []);
if (gpu_ids.length === 0) {
return {
gpu_selector: null
};
}
const valueMap = new Map<string, string>();
gpuOptions?.forEach((item) => {
item.children?.forEach((child: any) => {
valueMap.set(child.value, item.value);
});
});
const gpuids: string[][] = gpu_ids
.map((id: string) => {
const parent = valueMap.get(id);
return parent ? [parent, id] : null;
})
.filter(Boolean) as string[][];
const result = data.backend === backendOptionsMap.voxBox ? gpuids[0] : gpuids;
return {
gpu_selector: {
gpu_ids: result
}
};
};