fix: backend is not updated after changing model

main
jialin 10 months ago
parent 28a84a90cf
commit b1d7bb9fd7

@ -102,6 +102,7 @@ const DataForm: React.FC<DataFormProps> = forwardRef((props, ref) => {
return modelTaskData;
};
// just for setting the model name or repo_id, and the backend, Since the model type is fixed.
const handleOnSelectModel = (selectModel: any) => {
let name = _.split(selectModel.name, '/').slice(-1)[0];
const reg = /(-gguf)$/i;
@ -117,12 +118,15 @@ const DataForm: React.FC<DataFormProps> = forwardRef((props, ref) => {
backend:
modelTaskData.type === modelTaskMap.audio
? backendOptionsMap.voxBox
: form.getFieldValue('backend')
: selectModel.isGGUF
? backendOptionsMap.llamaBox
: backendOptionsMap.vllm
});
} else {
form.setFieldsValue({
ollama_library_model_name: selectModel.name,
name: name
name: name,
backend: backendOptionsMap.llamaBox
});
}
};

@ -82,7 +82,8 @@ const AddModal: FC<AddModalProps> = (props) => {
handleEvaluate,
handleOnValuesChange,
checkTokenRef,
warningStatus
warningStatus,
submitAnyway
} = useCheckCompatibility();
const form = useRef<any>({});
const intl = useIntl();
@ -90,7 +91,6 @@ const AddModal: FC<AddModalProps> = (props) => {
const [collapsed, setCollapsed] = useState<boolean>(false);
const [isGGUF, setIsGGUF] = useState<boolean>(props.isGGUF || false);
const modelFileRef = useRef<any>(null);
const submitAnyway = useRef<boolean>(false);
const handleSelectModelFile = useCallback((item: any) => {
form.current?.setFieldsValue?.({
@ -103,10 +103,11 @@ const AddModal: FC<AddModalProps> = (props) => {
}
}, []);
const handleOnSelectModel = (item: any, isgguf?: boolean) => {
const handleOnSelectModel = (item: any) => {
setSelectedModel(item);
form.current?.handleOnSelectModel?.(item);
if (!isgguf) {
if (!item.isGGUF) {
setIsGGUF(false);
handleShowCompatibleAlert(item.evaluateResult);
form.current?.setFieldsValue?.({
...item.evaluateResult?.default_spec
@ -149,7 +150,7 @@ const AddModal: FC<AddModalProps> = (props) => {
};
// trigger from local_path change or backend change
const handleBackendChangeHook = async () => {
const handleBackendChangeBefore = async () => {
const localPath = form.current.form.getFieldValue?.('local_path');
const backend = form.current.form.getFieldValue?.('backend');
@ -175,7 +176,7 @@ const AddModal: FC<AddModalProps> = (props) => {
};
const handleBackendChange = async (backend: string) => {
handleBackendChangeHook();
handleBackendChangeBefore();
if (backend === backendOptionsMap.vllm) {
setIsGGUF(false);
}

@ -32,7 +32,7 @@ interface SearchInputProps {
isDownload?: boolean;
setLoadingModel?: (flag: boolean) => void;
onSourceChange?: (source: string) => void;
onSelectModel: (model: any, isGGUF?: boolean) => void;
onSelectModel: (model: any) => void;
}
const SearchModel: React.FC<SearchInputProps> = (props) => {
@ -98,7 +98,7 @@ const SearchModel: React.FC<SearchInputProps> = (props) => {
};
const handleOnSelectModel = (item: any) => {
onSelectModel(item, checkIsGGUF(item));
onSelectModel(item);
setCurrent(item.id);
};
@ -121,7 +121,9 @@ const SearchModel: React.FC<SearchInputProps> = (props) => {
return {
...item,
value: item.name,
label: item.name
label: item.name,
isGGUF: checkIsGGUF(item),
source: modelSourceMap.modelscope_value
};
});
return list;
@ -157,7 +159,9 @@ const SearchModel: React.FC<SearchInputProps> = (props) => {
revision: item.Revision,
task: item.Tasks?.map((sItem: any) => sItem.Name).join(','),
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
const handleBackendChangeHook = async () => {
const handleBackendChangeBefore = async () => {
const localPath = form.getFieldValue?.('local_path');
const backend = form.getFieldValue?.('backend');
@ -118,7 +118,7 @@ const UpdateModal: React.FC<AddModalProps> = (props) => {
}
form.setFieldValue('backend_version', '');
handleSetGPUIds(val);
handleBackendChangeHook();
handleBackendChangeBefore();
};
const handleOnFocus = () => {

@ -214,6 +214,8 @@ export const useCheckCompatibility = () => {
const intl = useIntl();
const checkTokenRef = useRef<any>(null);
const submitAnyway = useRef<boolean>(false);
const requestIdRef = useRef(0);
const [warningStatus, setWarningStatus] = useState<{
show: boolean;
title?: string;
@ -225,6 +227,11 @@ export const useCheckCompatibility = () => {
message: []
});
const updateRequestId = () => {
requestIdRef.current += 1;
return requestIdRef.current;
};
const handleEvaluate = async (data: any) => {
try {
checkTokenRef.current?.cancel();
@ -392,11 +399,15 @@ export const useCheckCompatibility = () => {
const data = getSourceRepoConfigValue(source, allValues);
const gpuSelector = generateGPUIds(data.values);
const currentRequestId = updateRequestId();
const evalutionData = await handleEvaluate({
...data.values,
...gpuSelector
});
handleShowCompatibleAlert?.(evalutionData);
if (currentRequestId === requestIdRef.current) {
handleShowCompatibleAlert?.(evalutionData);
}
}
};
@ -415,6 +426,7 @@ export const useCheckCompatibility = () => {
handleOnValuesChange: debounceHandleValuesChange,
warningStatus,
checkTokenRef,
submitAnyway,
generateGPUIds,
handleEvaluate,
setWarningStatus

@ -18,7 +18,6 @@ import {
} from '@/pages/llmodels/config';
import { identifyModelTask } from '@/pages/llmodels/config/audio-catalog';
import {
generateSource,
modalConfig,
modelFileActions,
onLineSourceOptions
@ -422,7 +421,9 @@ const ModelFiles = () => {
{intl.formatMessage({ id: 'models.form.localPath' })}
</AutoTooltip>
) : (
<AutoTooltip ghost>{generateSource(record)}</AutoTooltip>
<AutoTooltip ghost>
{_.get(modelSourceMap, record.source, '')}
</AutoTooltip>
)}
</span>
)
@ -467,7 +468,7 @@ const ModelFiles = () => {
record.resolved_paths?.length > 0 && (
<PathWrapper>
<AutoTooltip ghost>
<span>{record.resolved_paths?.[0]}</span>
<span>{getResolvedPath(record.resolved_paths)}</span>
</AutoTooltip>
<span className="btn-wrapper">
<CopyButton

Loading…
Cancel
Save