mirror of
https://github.com/labring/FastGPT.git
synced 2025-07-24 22:03:54 +00:00
feat: Add support for independent loading states to optimize user experience during model testing (#4366)
* feat: 添加独立的loading状态支持,优化模型测试过程中的用户体验 * fix: typo * refactor: 修改loading状态字段名称,提升代码可读性 * feat: optimize model testing functionality, integrate loading state management, improve user experience
This commit is contained in:
@@ -33,6 +33,7 @@ type ModelTestItem = {
|
|||||||
status: 'waiting' | 'running' | 'success' | 'error';
|
status: 'waiting' | 'running' | 'success' | 'error';
|
||||||
message?: string;
|
message?: string;
|
||||||
duration?: number;
|
duration?: number;
|
||||||
|
loading?: boolean; // 单个模型的loading状态
|
||||||
};
|
};
|
||||||
|
|
||||||
const ModelTest = ({
|
const ModelTest = ({
|
||||||
@@ -85,7 +86,8 @@ const ModelTest = ({
|
|||||||
</HStack>
|
</HStack>
|
||||||
),
|
),
|
||||||
model: modelData.model,
|
model: modelData.model,
|
||||||
status: 'waiting'
|
status: 'waiting',
|
||||||
|
loading: false
|
||||||
};
|
};
|
||||||
})
|
})
|
||||||
.filter(Boolean) as ModelTestItem[];
|
.filter(Boolean) as ModelTestItem[];
|
||||||
@@ -93,14 +95,16 @@ const ModelTest = ({
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
const { runAsync: onStartTest, loading: isTesting } = useRequest2(
|
const { runAsync: onStartTest, loading: isAnyModelLoading } = useRequest2(
|
||||||
async () => {
|
async () => {
|
||||||
{
|
try {
|
||||||
let errorNum = 0;
|
let errorNum = 0;
|
||||||
const testModel = async (model: string) => {
|
const testModel = async (model: string) => {
|
||||||
setTestModelList((prev) =>
|
setTestModelList((prev) =>
|
||||||
prev.map((item) =>
|
prev.map((item) =>
|
||||||
item.model === model ? { ...item, status: 'running', message: '' } : item
|
item.model === model
|
||||||
|
? { ...item, status: 'running', message: '', loading: true }
|
||||||
|
: item
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
const start = Date.now();
|
const start = Date.now();
|
||||||
@@ -110,7 +114,7 @@ const ModelTest = ({
|
|||||||
setTestModelList((prev) =>
|
setTestModelList((prev) =>
|
||||||
prev.map((item) =>
|
prev.map((item) =>
|
||||||
item.model === model
|
item.model === model
|
||||||
? { ...item, status: 'success', duration: duration / 1000 }
|
? { ...item, status: 'success', duration: duration / 1000, loading: false }
|
||||||
: item
|
: item
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
@@ -118,7 +122,7 @@ const ModelTest = ({
|
|||||||
setTestModelList((prev) =>
|
setTestModelList((prev) =>
|
||||||
prev.map((item) =>
|
prev.map((item) =>
|
||||||
item.model === model
|
item.model === model
|
||||||
? { ...item, status: 'error', message: getErrText(error) }
|
? { ...item, status: 'error', message: getErrText(error), loading: false }
|
||||||
: item
|
: item
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
@@ -138,19 +142,22 @@ const ModelTest = ({
|
|||||||
title: t('account_model:test_failed', { num: errorNum })
|
title: t('account_model:test_failed', { num: errorNum })
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
} catch (error) {
|
||||||
|
console.error('Error during model testing:', error);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
refreshDeps: [testModelList]
|
refreshDeps: [testModelList]
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
const { runAsync: onTestOneModel, loading: testingOneModel } = useRequest2(
|
const { runAsync: onTestOneModel, loading: testingOneModel } = useRequest2(
|
||||||
async (model: string) => {
|
async (model: string) => {
|
||||||
const start = Date.now();
|
const start = Date.now();
|
||||||
|
|
||||||
setTestModelList((prev) =>
|
setTestModelList((prev) =>
|
||||||
prev.map((item) =>
|
prev.map((item) =>
|
||||||
item.model === model ? { ...item, status: 'running', message: '' } : item
|
item.model === model ? { ...item, status: 'running', message: '', loading: true } : item
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
@@ -160,13 +167,17 @@ const ModelTest = ({
|
|||||||
|
|
||||||
setTestModelList((prev) =>
|
setTestModelList((prev) =>
|
||||||
prev.map((item) =>
|
prev.map((item) =>
|
||||||
item.model === model ? { ...item, status: 'success', duration: duration / 1000 } : item
|
item.model === model
|
||||||
|
? { ...item, status: 'success', duration: duration / 1000, loading: false }
|
||||||
|
: item
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
setTestModelList((prev) =>
|
setTestModelList((prev) =>
|
||||||
prev.map((item) =>
|
prev.map((item) =>
|
||||||
item.model === model ? { ...item, status: 'error', message: getErrText(error) } : item
|
item.model === model
|
||||||
|
? { ...item, status: 'error', message: getErrText(error), loading: false }
|
||||||
|
: item
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@@ -176,8 +187,6 @@ const ModelTest = ({
|
|||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
const isTestLoading = testingOneModel || isTesting;
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<MyModal
|
<MyModal
|
||||||
iconSrc={'core/chat/sendLight'}
|
iconSrc={'core/chat/sendLight'}
|
||||||
@@ -222,12 +231,10 @@ const ModelTest = ({
|
|||||||
</Td>
|
</Td>
|
||||||
<Td>
|
<Td>
|
||||||
<MyIconButton
|
<MyIconButton
|
||||||
isLoading={isTestLoading}
|
isLoading={item.loading}
|
||||||
icon={'core/chat/sendLight'}
|
icon={'core/chat/sendLight'}
|
||||||
tip={t('account:model.test_model')}
|
tip={t('account:model.test_model')}
|
||||||
onClick={() => {
|
onClick={() => onTestOneModel(item.model)}
|
||||||
onTestOneModel(item.model);
|
|
||||||
}}
|
|
||||||
/>
|
/>
|
||||||
</Td>
|
</Td>
|
||||||
</Tr>
|
</Tr>
|
||||||
@@ -241,7 +248,11 @@ const ModelTest = ({
|
|||||||
<Button mr={4} variant={'whiteBase'} onClick={onClose}>
|
<Button mr={4} variant={'whiteBase'} onClick={onClose}>
|
||||||
{t('common:common.Cancel')}
|
{t('common:common.Cancel')}
|
||||||
</Button>
|
</Button>
|
||||||
<Button isLoading={isTestLoading} variant={'primary'} onClick={onStartTest}>
|
<Button
|
||||||
|
isLoading={isAnyModelLoading || testingOneModel}
|
||||||
|
variant={'primary'}
|
||||||
|
onClick={onStartTest}
|
||||||
|
>
|
||||||
{t('account_model:start_test', { num: testModelList.length })}
|
{t('account_model:start_test', { num: testModelList.length })}
|
||||||
</Button>
|
</Button>
|
||||||
</ModalFooter>
|
</ModalFooter>
|
||||||
|
Reference in New Issue
Block a user