fix: avoid sending all files when evaluating
This commit is contained in:
@@ -1,5 +1,5 @@
|
|||||||
import useUserSettings from '@/hooks/use-user-settings';
|
import useUserSettings from '@/hooks/use-user-settings';
|
||||||
import React from 'react';
|
import React, { useEffect } from 'react';
|
||||||
import SimpleBar from 'simplebar-react';
|
import SimpleBar from 'simplebar-react';
|
||||||
import 'simplebar-react/dist/simplebar.min.css';
|
import 'simplebar-react/dist/simplebar.min.css';
|
||||||
import styled from 'styled-components';
|
import styled from 'styled-components';
|
||||||
@@ -21,17 +21,49 @@ interface SimpleOverlayProps {
|
|||||||
height?: string | number;
|
height?: string | number;
|
||||||
children?: React.ReactNode;
|
children?: React.ReactNode;
|
||||||
style?: React.CSSProperties;
|
style?: React.CSSProperties;
|
||||||
|
onScrollEnd?: (e: React.UIEvent<HTMLDivElement>) => void;
|
||||||
|
disableTrigger?: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
const SimpleOverlay: React.FC<SimpleOverlayProps> = ({
|
const SimpleOverlay: React.FC<SimpleOverlayProps> = ({
|
||||||
height,
|
height,
|
||||||
children,
|
children,
|
||||||
style
|
style,
|
||||||
|
disableTrigger,
|
||||||
|
onScrollEnd
|
||||||
}) => {
|
}) => {
|
||||||
const { isDarkTheme } = useUserSettings();
|
const { isDarkTheme } = useUserSettings();
|
||||||
|
const simpleBarRef = React.useRef<any>(null);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
// simpleBarRef.current.recalculate();
|
||||||
|
|
||||||
|
const onScroll = (e: React.UIEvent<HTMLDivElement>) => {
|
||||||
|
const scrollElement = simpleBarRef.current?.getScrollElement();
|
||||||
|
const scrollHeight = scrollElement.scrollHeight;
|
||||||
|
const clientHeight = scrollElement.clientHeight;
|
||||||
|
const scrollTop = scrollElement.scrollTop;
|
||||||
|
|
||||||
|
// Check if the scrollbar is at the bottom 20px for buffer
|
||||||
|
const isAtBottom = scrollHeight - clientHeight - scrollTop <= 20;
|
||||||
|
if (isAtBottom && !disableTrigger) {
|
||||||
|
onScrollEnd?.(e);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
simpleBarRef.current
|
||||||
|
?.getScrollElement()
|
||||||
|
.addEventListener('scroll', onScroll);
|
||||||
|
|
||||||
|
return () => {
|
||||||
|
simpleBarRef.current
|
||||||
|
?.getScrollElement()
|
||||||
|
.removeEventListener('scroll', onScroll);
|
||||||
|
};
|
||||||
|
}, [height, disableTrigger, onScrollEnd]);
|
||||||
return (
|
return (
|
||||||
<Wrapper className={isDarkTheme ? 'dark' : 'light'}>
|
<Wrapper className={isDarkTheme ? 'dark' : 'light'}>
|
||||||
<SimpleBar
|
<SimpleBar
|
||||||
|
ref={simpleBarRef}
|
||||||
style={{
|
style={{
|
||||||
height: height,
|
height: height,
|
||||||
...style
|
...style
|
||||||
|
|||||||
@@ -32,7 +32,8 @@ const resetFields = [
|
|||||||
'cpu_offloading',
|
'cpu_offloading',
|
||||||
'distributed_inference_across_workers',
|
'distributed_inference_across_workers',
|
||||||
'backend_version',
|
'backend_version',
|
||||||
'backend_parameters'
|
'backend_parameters',
|
||||||
|
'env'
|
||||||
];
|
];
|
||||||
|
|
||||||
const ModalFooterStyle = {
|
const ModalFooterStyle = {
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
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';
|
||||||
@@ -9,6 +10,7 @@ import React, {
|
|||||||
useCallback,
|
useCallback,
|
||||||
useEffect,
|
useEffect,
|
||||||
useImperativeHandle,
|
useImperativeHandle,
|
||||||
|
useMemo,
|
||||||
useRef,
|
useRef,
|
||||||
useState
|
useState
|
||||||
} from 'react';
|
} from 'react';
|
||||||
@@ -54,13 +56,7 @@ 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 {
|
const { collapsed, modelSource, isDownload, displayEvaluateStatus } = props;
|
||||||
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>({
|
||||||
@@ -83,6 +79,7 @@ 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);
|
||||||
@@ -232,7 +229,7 @@ const HFModelFile: React.FC<HFModelFileProps> = forwardRef((props, ref) => {
|
|||||||
}
|
}
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
const handleEvaluate = async (list: any[]) => {
|
const handleEvaluate = async (list: any[], first?: boolean) => {
|
||||||
if (isDownload) {
|
if (isDownload) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -259,7 +256,8 @@ 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(
|
||||||
@@ -275,7 +273,10 @@ const HFModelFile: React.FC<HFModelFileProps> = forwardRef((props, ref) => {
|
|||||||
if (currentItem) {
|
if (currentItem) {
|
||||||
handleSelectModelFile(currentItem, true);
|
handleSelectModelFile(currentItem, true);
|
||||||
}
|
}
|
||||||
setDataSource({ fileList: resultList, loading: false });
|
setDataSource({
|
||||||
|
fileList: first ? resultList : [...dataSource.fileList, ...resultList],
|
||||||
|
loading: false
|
||||||
|
});
|
||||||
setIsEvaluating(false);
|
setIsEvaluating(false);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
setIsEvaluating(false);
|
setIsEvaluating(false);
|
||||||
@@ -318,10 +319,14 @@ const HFModelFile: React.FC<HFModelFileProps> = forwardRef((props, ref) => {
|
|||||||
return sortType === 'size' ? item.size : item.path;
|
return sortType === 'size' ? item.size : item.path;
|
||||||
});
|
});
|
||||||
|
|
||||||
handleSelectModelFile(sortList[0]);
|
cacheSortListRef.current = sortList;
|
||||||
setDataSource({ fileList: sortList, loading: false });
|
|
||||||
|
|
||||||
handleEvaluate(sortList);
|
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({});
|
||||||
@@ -348,12 +353,28 @@ 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({});
|
||||||
}
|
}
|
||||||
@@ -399,7 +420,11 @@ const HFModelFile: React.FC<HFModelFileProps> = forwardRef((props, ref) => {
|
|||||||
></Spin>
|
></Spin>
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
<SimpleOverlay height={collapsed ? 'max-content' : 'calc(100vh - 300px)'}>
|
<SimpleOverlay
|
||||||
|
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>
|
||||||
@@ -408,7 +433,7 @@ const HFModelFile: React.FC<HFModelFileProps> = forwardRef((props, ref) => {
|
|||||||
<ModelFileItem
|
<ModelFileItem
|
||||||
key={item.path}
|
key={item.path}
|
||||||
data={item}
|
data={item}
|
||||||
isEvaluating={isEvaluating}
|
isEvaluating={isEvaluating && !item.done}
|
||||||
active={item.path === current}
|
active={item.path === current}
|
||||||
handleSelectModelFile={handleSelectModelFile}
|
handleSelectModelFile={handleSelectModelFile}
|
||||||
handleOnEnter={handleOnEnter}
|
handleOnEnter={handleOnEnter}
|
||||||
@@ -428,6 +453,15 @@ 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>
|
||||||
|
|||||||
@@ -592,10 +592,6 @@ const options = [
|
|||||||
{
|
{
|
||||||
label: '--context-shift',
|
label: '--context-shift',
|
||||||
value: '--context-shift'
|
value: '--context-shift'
|
||||||
},
|
|
||||||
{
|
|
||||||
label: '--v2',
|
|
||||||
value: '--v2'
|
|
||||||
}
|
}
|
||||||
];
|
];
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user