fix: backend is not updated after changing model

This commit is contained in:
jialin
2025-04-02 11:24:26 +08:00
parent 28a84a90cf
commit b1d7bb9fd7
6 changed files with 40 additions and 18 deletions
+6 -2
View File
@@ -102,6 +102,7 @@ const DataForm: React.FC<DataFormProps> = forwardRef((props, ref) => {
return modelTaskData; return modelTaskData;
}; };
// just for setting the model name or repo_id, and the backend, Since the model type is fixed.
const handleOnSelectModel = (selectModel: any) => { const handleOnSelectModel = (selectModel: any) => {
let name = _.split(selectModel.name, '/').slice(-1)[0]; let name = _.split(selectModel.name, '/').slice(-1)[0];
const reg = /(-gguf)$/i; const reg = /(-gguf)$/i;
@@ -117,12 +118,15 @@ const DataForm: React.FC<DataFormProps> = forwardRef((props, ref) => {
backend: backend:
modelTaskData.type === modelTaskMap.audio modelTaskData.type === modelTaskMap.audio
? backendOptionsMap.voxBox ? backendOptionsMap.voxBox
: form.getFieldValue('backend') : selectModel.isGGUF
? backendOptionsMap.llamaBox
: backendOptionsMap.vllm
}); });
} else { } else {
form.setFieldsValue({ form.setFieldsValue({
ollama_library_model_name: selectModel.name, ollama_library_model_name: selectModel.name,
name: name name: name,
backend: backendOptionsMap.llamaBox
}); });
} }
}; };
@@ -82,7 +82,8 @@ const AddModal: FC<AddModalProps> = (props) => {
handleEvaluate, handleEvaluate,
handleOnValuesChange, handleOnValuesChange,
checkTokenRef, checkTokenRef,
warningStatus warningStatus,
submitAnyway
} = useCheckCompatibility(); } = useCheckCompatibility();
const form = useRef<any>({}); const form = useRef<any>({});
const intl = useIntl(); const intl = useIntl();
@@ -90,7 +91,6 @@ const AddModal: FC<AddModalProps> = (props) => {
const [collapsed, setCollapsed] = useState<boolean>(false); const [collapsed, setCollapsed] = useState<boolean>(false);
const [isGGUF, setIsGGUF] = useState<boolean>(props.isGGUF || false); const [isGGUF, setIsGGUF] = useState<boolean>(props.isGGUF || false);
const modelFileRef = useRef<any>(null); const modelFileRef = useRef<any>(null);
const submitAnyway = useRef<boolean>(false);
const handleSelectModelFile = useCallback((item: any) => { const handleSelectModelFile = useCallback((item: any) => {
form.current?.setFieldsValue?.({ form.current?.setFieldsValue?.({
@@ -103,10 +103,11 @@ const AddModal: FC<AddModalProps> = (props) => {
} }
}, []); }, []);
const handleOnSelectModel = (item: any, isgguf?: boolean) => { const handleOnSelectModel = (item: any) => {
setSelectedModel(item); setSelectedModel(item);
form.current?.handleOnSelectModel?.(item); form.current?.handleOnSelectModel?.(item);
if (!isgguf) { if (!item.isGGUF) {
setIsGGUF(false);
handleShowCompatibleAlert(item.evaluateResult); handleShowCompatibleAlert(item.evaluateResult);
form.current?.setFieldsValue?.({ form.current?.setFieldsValue?.({
...item.evaluateResult?.default_spec ...item.evaluateResult?.default_spec
@@ -149,7 +150,7 @@ const AddModal: FC<AddModalProps> = (props) => {
}; };
// trigger from local_path change or backend change // trigger from local_path change or backend change
const handleBackendChangeHook = async () => { const handleBackendChangeBefore = async () => {
const localPath = form.current.form.getFieldValue?.('local_path'); const localPath = form.current.form.getFieldValue?.('local_path');
const backend = form.current.form.getFieldValue?.('backend'); const backend = form.current.form.getFieldValue?.('backend');
@@ -175,7 +176,7 @@ const AddModal: FC<AddModalProps> = (props) => {
}; };
const handleBackendChange = async (backend: string) => { const handleBackendChange = async (backend: string) => {
handleBackendChangeHook(); handleBackendChangeBefore();
if (backend === backendOptionsMap.vllm) { if (backend === backendOptionsMap.vllm) {
setIsGGUF(false); setIsGGUF(false);
} }
@@ -32,7 +32,7 @@ interface SearchInputProps {
isDownload?: boolean; isDownload?: boolean;
setLoadingModel?: (flag: boolean) => void; setLoadingModel?: (flag: boolean) => void;
onSourceChange?: (source: string) => void; onSourceChange?: (source: string) => void;
onSelectModel: (model: any, isGGUF?: boolean) => void; onSelectModel: (model: any) => void;
} }
const SearchModel: React.FC<SearchInputProps> = (props) => { const SearchModel: React.FC<SearchInputProps> = (props) => {
@@ -98,7 +98,7 @@ const SearchModel: React.FC<SearchInputProps> = (props) => {
}; };
const handleOnSelectModel = (item: any) => { const handleOnSelectModel = (item: any) => {
onSelectModel(item, checkIsGGUF(item)); onSelectModel(item);
setCurrent(item.id); setCurrent(item.id);
}; };
@@ -121,7 +121,9 @@ const SearchModel: React.FC<SearchInputProps> = (props) => {
return { return {
...item, ...item,
value: item.name, value: item.name,
label: item.name label: item.name,
isGGUF: checkIsGGUF(item),
source: modelSourceMap.modelscope_value
}; };
}); });
return list; return list;
@@ -157,7 +159,9 @@ const SearchModel: React.FC<SearchInputProps> = (props) => {
revision: item.Revision, revision: item.Revision,
task: item.Tasks?.map((sItem: any) => sItem.Name).join(','), task: item.Tasks?.map((sItem: any) => sItem.Name).join(','),
tags: item.Tags, tags: item.Tags,
libraries: item.Libraries libraries: item.Libraries,
isGGUF: checkIsGGUF({ tags: item.Tags, libraries: item.Libraries }),
source: modelSourceMap.modelscope_value
}; };
}); });
@@ -84,7 +84,7 @@ const UpdateModal: React.FC<AddModalProps> = (props) => {
}; };
// trigger from local_path change or backend change // trigger from local_path change or backend change
const handleBackendChangeHook = async () => { const handleBackendChangeBefore = async () => {
const localPath = form.getFieldValue?.('local_path'); const localPath = form.getFieldValue?.('local_path');
const backend = form.getFieldValue?.('backend'); const backend = form.getFieldValue?.('backend');
@@ -118,7 +118,7 @@ const UpdateModal: React.FC<AddModalProps> = (props) => {
} }
form.setFieldValue('backend_version', ''); form.setFieldValue('backend_version', '');
handleSetGPUIds(val); handleSetGPUIds(val);
handleBackendChangeHook(); handleBackendChangeBefore();
}; };
const handleOnFocus = () => { const handleOnFocus = () => {
+13 -1
View File
@@ -214,6 +214,8 @@ export const useCheckCompatibility = () => {
const intl = useIntl(); const intl = useIntl();
const checkTokenRef = useRef<any>(null); const checkTokenRef = useRef<any>(null);
const submitAnyway = useRef<boolean>(false);
const requestIdRef = useRef(0);
const [warningStatus, setWarningStatus] = useState<{ const [warningStatus, setWarningStatus] = useState<{
show: boolean; show: boolean;
title?: string; title?: string;
@@ -225,6 +227,11 @@ export const useCheckCompatibility = () => {
message: [] message: []
}); });
const updateRequestId = () => {
requestIdRef.current += 1;
return requestIdRef.current;
};
const handleEvaluate = async (data: any) => { const handleEvaluate = async (data: any) => {
try { try {
checkTokenRef.current?.cancel(); checkTokenRef.current?.cancel();
@@ -392,11 +399,15 @@ export const useCheckCompatibility = () => {
const data = getSourceRepoConfigValue(source, allValues); const data = getSourceRepoConfigValue(source, allValues);
const gpuSelector = generateGPUIds(data.values); const gpuSelector = generateGPUIds(data.values);
const currentRequestId = updateRequestId();
const evalutionData = await handleEvaluate({ const evalutionData = await handleEvaluate({
...data.values, ...data.values,
...gpuSelector ...gpuSelector
}); });
handleShowCompatibleAlert?.(evalutionData);
if (currentRequestId === requestIdRef.current) {
handleShowCompatibleAlert?.(evalutionData);
}
} }
}; };
@@ -415,6 +426,7 @@ export const useCheckCompatibility = () => {
handleOnValuesChange: debounceHandleValuesChange, handleOnValuesChange: debounceHandleValuesChange,
warningStatus, warningStatus,
checkTokenRef, checkTokenRef,
submitAnyway,
generateGPUIds, generateGPUIds,
handleEvaluate, handleEvaluate,
setWarningStatus setWarningStatus
@@ -18,7 +18,6 @@ import {
} from '@/pages/llmodels/config'; } from '@/pages/llmodels/config';
import { identifyModelTask } from '@/pages/llmodels/config/audio-catalog'; import { identifyModelTask } from '@/pages/llmodels/config/audio-catalog';
import { import {
generateSource,
modalConfig, modalConfig,
modelFileActions, modelFileActions,
onLineSourceOptions onLineSourceOptions
@@ -422,7 +421,9 @@ const ModelFiles = () => {
{intl.formatMessage({ id: 'models.form.localPath' })} {intl.formatMessage({ id: 'models.form.localPath' })}
</AutoTooltip> </AutoTooltip>
) : ( ) : (
<AutoTooltip ghost>{generateSource(record)}</AutoTooltip> <AutoTooltip ghost>
{_.get(modelSourceMap, record.source, '')}
</AutoTooltip>
)} )}
</span> </span>
) )
@@ -467,7 +468,7 @@ const ModelFiles = () => {
record.resolved_paths?.length > 0 && ( record.resolved_paths?.length > 0 && (
<PathWrapper> <PathWrapper>
<AutoTooltip ghost> <AutoTooltip ghost>
<span>{record.resolved_paths?.[0]}</span> <span>{getResolvedPath(record.resolved_paths)}</span>
</AutoTooltip> </AutoTooltip>
<span className="btn-wrapper"> <span className="btn-wrapper">
<CopyButton <CopyButton