fix: update evaluation result issue

This commit is contained in:
jialin
2025-06-24 20:47:27 +08:00
parent 5f7df3f871
commit 830ee45161
7 changed files with 153 additions and 99 deletions
+15 -1
View File
@@ -1,4 +1,18 @@
import { atom } from 'jotai'; import { atom, getDefaultStore } from 'jotai';
// models expand keys: create, update , delete, // models expand keys: create, update , delete,
export const modelsExpandKeysAtom = atom<string[]>([]); export const modelsExpandKeysAtom = atom<string[]>([]);
export const requestIdAtom = atom<number>(0);
export const setRquestId = () => {
const store = getDefaultStore();
const id = Date.now();
store.set(requestIdAtom, id);
return id;
};
export const getRequestId = () => {
const store = getDefaultStore();
return store.get(requestIdAtom);
};
+10 -1
View File
@@ -277,6 +277,14 @@ body {
display: none; display: none;
} }
.ant-pro-base-menu-vertical-item-title {
// height: var(--ant-menu-item-height) !important;
}
.ant-pro-base-menu-vertical-item-title-collapsed {
// height: var(--ant-menu-item-height) !important;
}
.ant-pro-layout { .ant-pro-layout {
height: 100vh; height: 100vh;
@@ -333,12 +341,13 @@ body {
} }
// ======== menu style end ============ // ======== menu style end ============
.ant-menu-submenu-popup { .ant-menu-submenu-popup {
.ant-menu-sub { .ant-menu-sub {
.ant-menu-item-only-child { .ant-menu-item-only-child {
height: 40px; height: 40px;
line-height: 40px; line-height: 40px;
color: var(--ant-color-text); // color: var(--ant-color-text);
.anticon { .anticon {
font-size: var(--font-size-middle); font-size: var(--font-size-middle);
+41 -16
View File
@@ -1,3 +1,4 @@
import { getRequestId } from '@/atoms/models';
import ModalFooter from '@/components/modal-footer'; import ModalFooter from '@/components/modal-footer';
import GSDrawer from '@/components/scroller-modal/gs-drawer'; import GSDrawer from '@/components/scroller-modal/gs-drawer';
import { PageActionType } from '@/config/types'; import { PageActionType } from '@/config/types';
@@ -116,7 +117,6 @@ const AddModal: FC<AddModalProps> = (props) => {
warningStatus, warningStatus,
submitAnyway submitAnyway
} = useCheckCompatibility(); } = useCheckCompatibility();
const { onSelectModel } = useSelectModel({ gpuOptions: props.gpuOptions }); const { onSelectModel } = useSelectModel({ gpuOptions: props.gpuOptions });
const form = useRef<any>({}); const form = useRef<any>({});
const intl = useIntl(); const intl = useIntl();
@@ -132,12 +132,18 @@ const AddModal: FC<AddModalProps> = (props) => {
requestModelId: 0 requestModelId: 0
}); });
const requestModelIdRef = useRef<number>(0); const requestModelIdRef = useRef<number>(0);
const currentSelectedModel = useRef<any>({});
const { run: fetchModelFiles } = useDeferredRequest( const { run: fetchModelFiles } = useDeferredRequest(
() => modelFileRef.current?.fetchModelFiles?.(), () => modelFileRef.current?.fetchModelFiles?.(),
100 100
); );
const updateSelectedModel = (model: any) => {
currentSelectedModel.current = model;
setSelectedModel(model);
};
/** /**
* Update the request model id to distinguish * Update the request model id to distinguish
* the evaluate request. * the evaluate request.
@@ -236,10 +242,14 @@ const AddModal: FC<AddModalProps> = (props) => {
); );
const handleSelectModelFile = async (item: any, requestModelId: number) => { const handleSelectModelFile = async (item: any, requestModelId: number) => {
if ( console.log(
evaluateStateRef.current.state !== EvaluateProccess.file || 'handleSelectModelFile:',
requestModelId !== evaluateStateRef.current.requestModelId item,
) { requestModelId,
getRequestId(),
evaluateStateRef.current
);
if (requestModelId !== getRequestId()) {
return; return;
} }
form.current?.form?.resetFields(resetFieldsByFile); form.current?.form?.resetFields(resetFieldsByFile);
@@ -251,7 +261,7 @@ const AddModal: FC<AddModalProps> = (props) => {
categories: getCategory(item) categories: getCategory(item)
}); });
console.log('handleSelectModelFile', item); console.log('handleSelectModelFile>>>>>>>>>>>>', item);
// evaluate the form data when select a model file // evaluate the form data when select a model file
if (item.fakeName) { if (item.fakeName) {
@@ -265,7 +275,7 @@ const AddModal: FC<AddModalProps> = (props) => {
}; };
const handleOnSelectModel = async (item: any) => { const handleOnSelectModel = async (item: any) => {
// If the item is empty or the same as the selected model, do nothing // If the item is empty or the same as the selected model, do nothing
console.log('handleOnSelectModel', item, selectedModel);
handleCancelFiles(); handleCancelFiles();
if ( if (
_.isEmpty(item) || _.isEmpty(item) ||
@@ -273,6 +283,7 @@ const AddModal: FC<AddModalProps> = (props) => {
) { ) {
return; return;
} }
console.log('handleOnSelectModel:', item, selectedModel);
setIsGGUF(item.isGGUF); setIsGGUF(item.isGGUF);
clearCahceFormValues(); clearCahceFormValues();
unlockWarningStatus(); unlockWarningStatus();
@@ -280,7 +291,7 @@ const AddModal: FC<AddModalProps> = (props) => {
state: EvaluateProccess.model, state: EvaluateProccess.model,
requestModelId: updateRequestModelId() requestModelId: updateRequestModelId()
}); });
setSelectedModel(item); updateSelectedModel(item);
form.current?.form?.resetFields(resetFieldsByModel); form.current?.form?.resetFields(resetFieldsByModel);
const modelInfo = onSelectModel(item, props.source); const modelInfo = onSelectModel(item, props.source);
@@ -306,9 +317,27 @@ const AddModal: FC<AddModalProps> = (props) => {
} }
}; };
const currentModelDuringEvaluate = (item: any) => {
return (
evaluateStateRef.current.state === EvaluateProccess.form &&
item.name === currentSelectedModel.current.name
);
};
const handleOnSelectModelAfterEvaluate = (item: any) => { const handleOnSelectModelAfterEvaluate = (item: any) => {
console.log(
'handleOnSelectModelAfterEvaluate:',
item.name,
currentSelectedModel.current.name,
warningStatus.type,
currentModelDuringEvaluate(item)
);
if (currentModelDuringEvaluate(item)) {
return;
}
// If the item is empty
setIsGGUF(item.isGGUF); setIsGGUF(item.isGGUF);
setSelectedModel(item); updateSelectedModel(item);
setEvaluteState({ setEvaluteState({
state: EvaluateProccess.model, state: EvaluateProccess.model,
requestModelId: updateRequestModelId() requestModelId: updateRequestModelId()
@@ -316,12 +345,6 @@ const AddModal: FC<AddModalProps> = (props) => {
handleCancelFiles(); handleCancelFiles();
const modelInfo = onSelectModel(item, props.source); const modelInfo = onSelectModel(item, props.source);
console.log(
'handleOnSelectModelAfterEvaluate',
item,
evaluateStateRef.current
);
if ( if (
evaluateStateRef.current.state === EvaluateProccess.model && evaluateStateRef.current.state === EvaluateProccess.model &&
item.evaluated item.evaluated
@@ -329,7 +352,9 @@ const AddModal: FC<AddModalProps> = (props) => {
handleShowCompatibleAlert(item.evaluateResult); handleShowCompatibleAlert(item.evaluateResult);
form.current?.setFieldsValue?.({ form.current?.setFieldsValue?.({
...getDefaultSpec(item), ...getDefaultSpec(item),
...modelInfo, ...(item.name === currentSelectedModel.current.name
? _.omit(modelInfo, ['name'])
: modelInfo),
categories: getCategory(item) categories: getCategory(item)
}); });
} }
@@ -1,3 +1,4 @@
import { getRequestId } from '@/atoms/models';
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';
@@ -283,7 +284,7 @@ const HFModelFile: React.FC<HFModelFileProps> = forwardRef((props, ref) => {
handleSelectModelFile({}); handleSelectModelFile({});
return; return;
} }
parentRequestModelId.current = updateEvaluteState?.('file'); parentRequestModelId.current = getRequestId();
checkTokenRef.current?.cancel?.(); checkTokenRef.current?.cancel?.();
axiosTokenRef.current?.abort?.(); axiosTokenRef.current?.abort?.();
axiosTokenRef.current = new AbortController(); axiosTokenRef.current = new AbortController();
@@ -292,12 +293,17 @@ const HFModelFile: React.FC<HFModelFileProps> = forwardRef((props, ref) => {
setCurrent(''); setCurrent('');
try { try {
let list = []; let list = [];
const currentParentRequestId = getRequestId();
if (modelSourceMap.huggingface_value === modelSource) { if (modelSourceMap.huggingface_value === modelSource) {
list = await getHuggingfaceFiles(); list = await getHuggingfaceFiles();
} else if (modelSourceMap.modelscope_value === modelSource) { } else if (modelSourceMap.modelscope_value === modelSource) {
list = await getModelScopeFiles(); list = await getModelScopeFiles();
} }
if (currentParentRequestId !== getRequestId()) {
return;
}
const newList = generateGroupByFilename(list); const newList = generateGroupByFilename(list);
const sortList = _.sortBy(newList, (item: any) => { const sortList = _.sortBy(newList, (item: any) => {
return sortType === 'size' ? item.size : item.path; return sortType === 'size' ? item.size : item.path;
+15 -2
View File
@@ -9,6 +9,7 @@ import {
RightOutlined RightOutlined
} from '@ant-design/icons'; } from '@ant-design/icons';
import { useIntl } from '@umijs/max'; import { useIntl } from '@umijs/max';
import { useBoolean } from 'ahooks';
import { Button, Empty, Spin, Tooltip } from 'antd'; import { Button, Empty, Spin, Tooltip } from 'antd';
import { some } from 'lodash'; import { some } from 'lodash';
import 'overlayscrollbars/overlayscrollbars.css'; import 'overlayscrollbars/overlayscrollbars.css';
@@ -72,6 +73,7 @@ const ModelCard: React.FC<{
loadingModel?: boolean; loadingModel?: boolean;
modelSource: string; modelSource: string;
}> = (props) => { }> = (props) => {
const [hideMd, { toggle }] = useBoolean();
const { onCollapse, setIsGGUF, collapsed, modelSource } = props; const { onCollapse, setIsGGUF, collapsed, modelSource } = props;
const intl = useIntl(); const intl = useIntl();
const requestSource = useRequestToken(); const requestSource = useRequestToken();
@@ -397,9 +399,20 @@ const ModelCard: React.FC<{
{readmeText && ( {readmeText && (
<> <>
<TitleWrapper> <TitleWrapper>
<div className="title">README.md</div> <div className="flex-center gap-8">
<span className="title">README.md</span>
{/* <Button
onClick={toggle}
size="small"
type="text"
icon={hideMd ? <EyeOutlined /> : <EyeInvisibleOutlined />}
></Button> */}
</div>
</TitleWrapper> </TitleWrapper>
<div className="card-wrapper"> <div
className="card-wrapper"
style={{ width: hideMd ? 0 : 'auto', overflow: 'hidden' }}
>
<MarkdownViewer <MarkdownViewer
generateImgLink={generateModeScopeImgLink} generateImgLink={generateModeScopeImgLink}
content={readmeText} content={readmeText}
+61 -77
View File
@@ -1,3 +1,4 @@
import { getRequestId, setRquestId } from '@/atoms/models';
import { createAxiosToken } from '@/hooks/use-chunk-request'; import { createAxiosToken } from '@/hooks/use-chunk-request';
import { QuestionCircleOutlined } from '@ant-design/icons'; import { QuestionCircleOutlined } from '@ant-design/icons';
import { useIntl } from '@umijs/max'; import { useIntl } from '@umijs/max';
@@ -68,6 +69,7 @@ const SearchModel: React.FC<SearchInputProps> = (props) => {
displayEvaluateStatus, displayEvaluateStatus,
unlockWarningStatus unlockWarningStatus
} = props; } = props;
const [dataSource, setDataSource] = useState<{ const [dataSource, setDataSource] = useState<{
repoOptions: any[]; repoOptions: any[];
loading: boolean; loading: boolean;
@@ -95,7 +97,7 @@ const SearchModel: React.FC<SearchInputProps> = (props) => {
const filterTaskRef = useRef<string>(''); const filterTaskRef = useRef<string>('');
const timer = useRef<any>(null); const timer = useRef<any>(null);
const requestIdRef = useRef<number>(0); const requestIdRef = useRef<number>(0);
const searchIdRef = useRef<number>(0); const searchRepoRequestIdRef = useRef<number>(0);
const [query, setQuery] = useState({ const [query, setQuery] = useState({
page: 1, page: 1,
perPage: 10, perPage: 10,
@@ -120,9 +122,9 @@ const SearchModel: React.FC<SearchInputProps> = (props) => {
} }
]); ]);
const updateSearchId = () => { const updateSearchRepoRequestId = () => {
searchIdRef.current += 1; searchRepoRequestIdRef.current += 1;
return searchIdRef.current; return searchRepoRequestIdRef.current;
}; };
const updateRequestId = () => { const updateRequestId = () => {
@@ -153,43 +155,32 @@ const SearchModel: React.FC<SearchInputProps> = (props) => {
// huggeface // huggeface
const getModelsFromHuggingface = async (sort: string) => { const getModelsFromHuggingface = async (sort: string) => {
const currentSearchId = updateSearchId(); const currentSearchId = setRquestId();
try { const task: any = searchInputRef.current ? '' : 'text-generation';
const task: any = searchInputRef.current ? '' : 'text-generation'; const params = {
const params = { search: {
search: { query: searchInputRef.current || '',
query: searchInputRef.current || '', sort: sort,
sort: sort, tags: filterGGUFRef.current ? ['gguf'] : [],
tags: filterGGUFRef.current ? ['gguf'] : [], task: HuggingFaceTaskMap[filterTaskRef.current] || task
task: HuggingFaceTaskMap[filterTaskRef.current] || task
}
};
const data = await queryHuggingfaceModels(params, {
signal: axiosTokenRef.current.signal
});
if (searchIdRef.current !== currentSearchId) {
return {
notSameRequest: true
};
} }
let list = _.map(data || [], (item: any) => { };
return { const data = await queryHuggingfaceModels(params, {
...item, signal: axiosTokenRef.current.signal
value: item.name, });
label: item.name, if (getRequestId() !== currentSearchId) {
isGGUF: checkIsGGUF(item), throw 'new request has been sent';
source: modelSource
};
});
return list;
} catch (error) {
if (searchIdRef.current !== currentSearchId) {
return {
notSameRequest: true
};
}
return [];
} }
let list = _.map(data || [], (item: any) => {
return {
...item,
value: item.name,
label: item.name,
isGGUF: checkIsGGUF(item),
source: modelSource
};
});
return list;
}; };
// modelscope, only modelscope has page and perPage // modelscope, only modelscope has page and perPage
@@ -198,7 +189,7 @@ const SearchModel: React.FC<SearchInputProps> = (props) => {
page: number; page: number;
perPage?: number; perPage?: number;
}) => { }) => {
const currentSearchId = updateSearchId(); const currentSearchId = setRquestId();
try { try {
const params = { const params = {
Name: `${searchInputRef.current}`, Name: `${searchInputRef.current}`,
@@ -213,11 +204,11 @@ const SearchModel: React.FC<SearchInputProps> = (props) => {
const data = await queryModelScopeModels(params, { const data = await queryModelScopeModels(params, {
signal: axiosTokenRef.current.signal signal: axiosTokenRef.current.signal
}); });
if (searchIdRef.current !== currentSearchId) {
return { if (getRequestId() !== currentSearchId) {
notSameRequest: true throw 'new request has been sent';
};
} }
let list = _.map(_.get(data, 'Data.Model.Models') || [], (item: any) => { let list = _.map(_.get(data, 'Data.Model.Models') || [], (item: any) => {
return { return {
path: item.Path, path: item.Path,
@@ -249,38 +240,28 @@ const SearchModel: React.FC<SearchInputProps> = (props) => {
}); });
return list; return list;
} catch (error) { } catch (error) {
if (searchIdRef.current !== currentSearchId) {
return {
notSameRequest: true
};
}
setQuery((prev) => { setQuery((prev) => {
return { return {
...prev, ...prev,
page: queryParams.page, page: queryParams.page
total: 0
}; };
}); });
return []; throw error;
} }
}; };
const getEvaluateResults = async (repoList: any[]) => { const getEvaluateResults = async (repoList: any[]) => {
try { checkTokenRef.current?.cancel?.();
checkTokenRef.current?.cancel?.(); checkTokenRef.current = createAxiosToken();
checkTokenRef.current = createAxiosToken(); const evaluations = await evaluationsModelSpec(
const evaluations = await evaluationsModelSpec( {
{ model_specs: repoList
model_specs: repoList },
}, {
{ token: checkTokenRef.current?.token
token: checkTokenRef.current?.token }
} );
); return evaluations.results;
return evaluations.results;
} catch (error) {
return [];
}
}; };
const handleEvaluate = async (list: any[]) => { const handleEvaluate = async (list: any[]) => {
@@ -288,6 +269,7 @@ const SearchModel: React.FC<SearchInputProps> = (props) => {
return; return;
} }
const currentRequestId = updateRequestId(); const currentRequestId = updateRequestId();
const currentSearchId = getRequestId();
try { try {
const repoList = list.map((item) => { const repoList = list.map((item) => {
const res = handleRecognizeAudioModel(item, modelSource); const res = handleRecognizeAudioModel(item, modelSource);
@@ -320,7 +302,11 @@ const SearchModel: React.FC<SearchInputProps> = (props) => {
setIsEvaluating(true); setIsEvaluating(true);
const evaluations = await getEvaluateResults(repoList); const evaluations = await getEvaluateResults(repoList);
if (requestIdRef.current !== currentRequestId) { // bind the requestId to the current request and searchId
if (
requestIdRef.current !== currentRequestId &&
currentSearchId !== getRequestId()
) {
return; return;
} }
const resultList = list.map((item, index) => { const resultList = list.map((item, index) => {
@@ -349,6 +335,7 @@ const SearchModel: React.FC<SearchInputProps> = (props) => {
onSelectModelAfterEvaluate(currentItem); onSelectModelAfterEvaluate(currentItem);
} }
} catch (error) { } catch (error) {
// cancel the corrponding request
if (requestIdRef.current === currentRequestId) { if (requestIdRef.current === currentRequestId) {
setIsEvaluating(false); setIsEvaluating(false);
} }
@@ -369,7 +356,8 @@ const SearchModel: React.FC<SearchInputProps> = (props) => {
if (!SUPPORTEDSOURCE.includes(modelSource)) { if (!SUPPORTEDSOURCE.includes(modelSource)) {
return; return;
} }
axiosTokenRef.current?.abort?.('new request'); const currentSearchId = updateSearchRepoRequestId();
axiosTokenRef.current?.abort?.('cancel previous request');
axiosTokenRef.current = new AbortController(); axiosTokenRef.current = new AbortController();
checkTokenRef.current?.cancel?.(); checkTokenRef.current?.cancel?.();
if (timer.current) { if (timer.current) {
@@ -386,9 +374,7 @@ const SearchModel: React.FC<SearchInputProps> = (props) => {
let list: any[] = []; let list: any[] = [];
if (modelSource === modelSourceMap.huggingface_value) { if (modelSource === modelSourceMap.huggingface_value) {
const resultList = await getModelsFromHuggingface(sort); const resultList = await getModelsFromHuggingface(sort);
if (resultList?.notSameRequest) {
return;
}
cacheRepoOptions.current = resultList; cacheRepoOptions.current = resultList;
// hf has no page and perPage, so we need to slice the resultList // hf has no page and perPage, so we need to slice the resultList
@@ -402,9 +388,7 @@ const SearchModel: React.FC<SearchInputProps> = (props) => {
}); });
} else if (modelSource === modelSourceMap.modelscope_value) { } else if (modelSource === modelSourceMap.modelscope_value) {
list = await getModelsFromModelscope(params); list = await getModelsFromModelscope(params);
if (list?.notSameRequest) { console.log('list:', list);
return;
}
cacheRepoOptions.current = list; cacheRepoOptions.current = list;
} }
@@ -423,12 +407,12 @@ const SearchModel: React.FC<SearchInputProps> = (props) => {
console.log('error:', error); console.log('error:', error);
setDataSource({ setDataSource({
repoOptions: [], repoOptions: [],
loading: false, loading: currentSearchId !== searchRepoRequestIdRef.current,
sortType: sort, sortType: sort,
networkError: error?.message === 'Failed to fetch' networkError: error?.message === 'Failed to fetch'
}); });
setLoadingModel?.(false); setLoadingModel?.(currentSearchId !== searchRepoRequestIdRef.current);
displayEvaluateStatus?.({ displayEvaluateStatus?.({
show: false, show: false,
message: '' message: ''
+4 -1
View File
@@ -502,7 +502,10 @@ export const useCheckCompatibility = () => {
}; };
}; };
const handleDoEvalute = async (formData: FormData) => { const handleDoEvalute = async (
formData: FormData,
evaluateProccess?: 'model' | 'file' | 'form'
) => {
const currentRequestId = updateRequestId(); const currentRequestId = updateRequestId();
const evalutionData = await handleEvaluate(formData); const evalutionData = await handleEvaluate(formData);