fix: remove evaluating for files

main
jialin 9 months ago
parent 1532f47da1
commit 2b7eb832ed

@ -1,4 +1,3 @@
import MoreButton from '@/components/buttons/more';
import SimpleOverlay from '@/components/simple-overlay';
import { createAxiosToken } from '@/hooks/use-chunk-request';
import { useIntl } from '@umijs/max';
@ -10,7 +9,6 @@ import React, {
useCallback,
useEffect,
useImperativeHandle,
useMemo,
useRef,
useState
} from 'react';
@ -56,7 +54,13 @@ const includeReg = /\.(safetensors|gguf)$/i;
const filterRegGGUF = /\.(gguf)$/i;
const HFModelFile: React.FC<HFModelFileProps> = forwardRef((props, ref) => {
const { collapsed, modelSource, isDownload, displayEvaluateStatus } = props;
const {
collapsed,
modelSource,
isDownload,
gpuOptions,
displayEvaluateStatus
} = props;
const intl = useIntl();
const [isEvaluating, setIsEvaluating] = useState(false);
const [dataSource, setDataSource] = useState<any>({
@ -79,7 +83,6 @@ const HFModelFile: React.FC<HFModelFileProps> = forwardRef((props, ref) => {
const axiosTokenRef = useRef<any>(null);
const checkTokenRef = useRef<any>(null);
const timer = useRef<any>(null);
const cacheSortListRef = useRef<any[]>([]);
const handleSelectModelFile = (item: any, evaluate?: boolean) => {
props.onSelectFile?.(item, evaluate);
@ -229,7 +232,7 @@ const HFModelFile: React.FC<HFModelFileProps> = forwardRef((props, ref) => {
}
}, []);
const handleEvaluate = async (list: any[], first?: boolean) => {
const handleEvaluate = async (list: any[]) => {
if (isDownload) {
return;
}
@ -256,8 +259,7 @@ const HFModelFile: React.FC<HFModelFileProps> = forwardRef((props, ref) => {
const resultList = _.map(list, (item: any, index: number) => {
return {
...item,
evaluateResult: evaluationList[index],
done: true
evaluateResult: evaluationList[index]
};
});
const currentItem = _.find(
@ -273,10 +275,7 @@ const HFModelFile: React.FC<HFModelFileProps> = forwardRef((props, ref) => {
if (currentItem) {
handleSelectModelFile(currentItem, true);
}
setDataSource({
fileList: first ? resultList : [...dataSource.fileList, ...resultList],
loading: false
});
setDataSource({ fileList: resultList, loading: false });
setIsEvaluating(false);
} catch (error) {
setIsEvaluating(false);
@ -299,12 +298,7 @@ const HFModelFile: React.FC<HFModelFileProps> = forwardRef((props, ref) => {
axiosTokenRef.current?.abort?.();
axiosTokenRef.current = new AbortController();
setDataSource({ ...dataSource, loading: true });
displayEvaluateStatus?.({
show: true,
flag: {
file: true
}
});
setCurrent('');
try {
let list = [];
@ -319,23 +313,11 @@ const HFModelFile: React.FC<HFModelFileProps> = forwardRef((props, ref) => {
return sortType === 'size' ? item.size : item.path;
});
cacheSortListRef.current = sortList;
const headList = cacheSortListRef.current.splice(0, 10);
handleSelectModelFile(headList[0]);
setDataSource({ fileList: headList, loading: false });
handleEvaluate(headList, true);
handleSelectModelFile(sortList[0]);
setDataSource({ fileList: sortList, loading: false });
} catch (error) {
setDataSource({ fileList: [], loading: false });
handleSelectModelFile({});
displayEvaluateStatus?.({
show: false,
flag: {
file: false
}
});
}
};
@ -353,28 +335,12 @@ const HFModelFile: React.FC<HFModelFileProps> = forwardRef((props, ref) => {
handleSelectModelFile(item);
}
};
const handleOnScrollEnd = () => {
const headList = cacheSortListRef.current.splice(0, 10);
if (headList.length) {
setDataSource({
...dataSource,
fileList: [...dataSource.fileList, ...headList]
});
handleEvaluate(headList);
}
};
useImperativeHandle(ref, () => ({
fetchModelFiles: handleFetchModelFiles
}));
const maxHeight = useMemo(() => {
return collapsed ? 'max-content' : 'calc(100vh - 300px)';
}, [collapsed]);
useEffect(() => {
if (!props.selectedModel?.name) {
if (!props.selectedModel.name) {
setDataSource({ fileList: [], loading: false });
handleSelectModelFile({});
}
@ -420,11 +386,7 @@ const HFModelFile: React.FC<HFModelFileProps> = forwardRef((props, ref) => {
></Spin>
</div>
)}
<SimpleOverlay
height={maxHeight}
onScrollEnd={handleOnScrollEnd}
disableTrigger={isEvaluating || dataSource.loading}
>
<SimpleOverlay height={collapsed ? 'max-content' : 'calc(100vh - 300px)'}>
<div style={{ padding: '16px 24px' }}>
{dataSource.fileList.length ? (
<ItemFileWrapper>
@ -433,7 +395,7 @@ const HFModelFile: React.FC<HFModelFileProps> = forwardRef((props, ref) => {
<ModelFileItem
key={item.path}
data={item}
isEvaluating={isEvaluating && !item.done}
isEvaluating={isEvaluating}
active={item.path === current}
handleSelectModelFile={handleSelectModelFile}
handleOnEnter={handleOnEnter}
@ -453,15 +415,6 @@ const HFModelFile: React.FC<HFModelFileProps> = forwardRef((props, ref) => {
/>
)
)}
<MoreButton
show={
cacheSortListRef.current.length > 0 &&
!dataSource.loading &&
!isEvaluating
}
loading={dataSource.loading || isEvaluating}
loadMore={handleOnScrollEnd}
></MoreButton>
</div>
</SimpleOverlay>
</div>

Loading…
Cancel
Save