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