Skip to content

Commit d6bd964

Browse files
committed
feature: test model
1 parent 757ae8a commit d6bd964

File tree

3 files changed

+318
-131
lines changed

3 files changed

+318
-131
lines changed

src/components/Check.vue

Lines changed: 203 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,7 @@
215215
</a-tooltip>
216216
</a-dropdown>
217217
</div>
218-
218+
<a-progress :percent="progressPercent" show-info size="small"/>
219219

220220
<div v-if="!isMobile" class="table-container">
221221
<a-table
@@ -231,12 +231,8 @@
231231
{{ record.status }}
232232
</template>
233233
<template v-else-if="column.dataIndex === 'model'">
234-
<span>
235-
📦 {{ record.model }}
236-
<CopyOutlined
237-
style="margin-left: 8px; cursor: pointer;"
238-
@click="copyText(record.model)"
239-
/>
234+
<span @click="copyText(item.model)">
235+
{{ record.model }}
240236
</span>
241237
</template>
242238
<template v-else-if="column.dataIndex === 'responseTime'">
@@ -303,13 +299,8 @@
303299
</div>
304300
<div class="list-item-field">
305301
<span class="field-label">{{ t('MODEL_NAME_LABEL') }}</span>
306-
<span class="field-value">
307-
📦 {{ item.model }}
308-
<CopyOutlined
309-
type="copy"
310-
style="margin-left: 8px; cursor: pointer;"
311-
@click="copyText(item.model)"
312-
/>
302+
<span class="field-value" @click="copyText(item.model)">
303+
{{ item.model }}
313304
</span>
314305
</div>
315306
<div class="list-item-field">
@@ -372,7 +363,7 @@
372363
</a-form>
373364
</a-modal>
374365
<a-modal
375-
v-model:open="showSettingsModal1"
366+
v-model:open="showAppSettingsModal"
376367
:title="t('SETTINGS_PANEL')"
377368
:footer="null"
378369
:width="600"
@@ -381,7 +372,7 @@
381372
:centered="true"
382373
>
383374
<a-tabs>
384-
<a-tab-pane key="1" :tab="t('LOCAL_CACHE')" style="overflow-x: hidden;">
375+
<a-tab-pane key="1" :tab="t('LOCAL_CACHE')" style="overflow-x: hidden;" tabPosition="left">
385376
<a-form @submit.prevent>
386377
<a-row :gutter="16">
387378
<a-col :span="16">
@@ -765,6 +756,7 @@ const chartContainer = ref(null);
765756
let chartInstance = null;
766757
const showSVGModal = ref(false);
767758
const svgDataUrl = ref('');
759+
768760
const appDescription = computed(() => {
769761
const currentLocale = locale.value || 'zh';
770762
return appInfo.description[currentLocale] || appInfo.description['zh'];
@@ -787,7 +779,7 @@ const paginatedData = computed(() => {
787779
return tableData.value.slice(start, end);
788780
});
789781
// 设置面板相关状态
790-
const showSettingsModal1 = ref(false);
782+
const showAppSettingsModal = ref(false);
791783
const showLoginModal = ref(false);
792784
793785
// 主题切换方法
@@ -1091,6 +1083,11 @@ const checkQuota = async () => {
10911083
checkQuota_spinning.value = false;
10921084
}
10931085
};
1086+
let modelNames=[]
1087+
const tableData = ref([]);
1088+
const totalModels = ref(0);
1089+
const completedModels = ref(0);
1090+
const progressPercent = ref(0);
10941091
10951092
// 添加 testModels 函数
10961093
async function testModels() {
@@ -1100,9 +1097,12 @@ async function testModels() {
11001097
results.inconsistent = [];
11011098
results.awaitOfficialVerification = [];
11021099
1103-
const apiUrlValue = apiUrl.value;
1100+
// 清空表格数据
1101+
tableData.value = [];
1102+
1103+
const apiUrlValue = apiUrl.value.replace(/\/+$/, '');
11041104
const apiKeyValue = apiKey.value;
1105-
const modelNames = modelName.value.split(',').map((m) => m.trim()).filter((m) => m);
1105+
const modelNames = selectedModels.value;
11061106
const timeout = parseInt(modelTimeout.value);
11071107
const concurrency = parseInt(modelConcurrency.value);
11081108
@@ -1111,32 +1111,64 @@ async function testModels() {
11111111
return;
11121112
}
11131113
1114+
// 显示结果容器
1115+
shouldShift.value = true;
1116+
showResultContainer.value = true;
1117+
1118+
// 初始化进度
1119+
totalModels.value = selectedModels.value.length;
1120+
completedModels.value = 0;
1121+
progressPercent.value = 0;
1122+
11141123
testModels_spinning.value = true;
11151124
11161125
try {
1117-
const testResults = await testModelList(
1126+
await testModelList(
11181127
apiUrlValue,
11191128
apiKeyValue,
11201129
modelNames,
11211130
timeout,
1122-
concurrency
1131+
concurrency,
1132+
(progress) => {
1133+
// 更新表格数据
1134+
updateTableData(progress);
1135+
// 更新进度
1136+
completedModels.value += 1;
1137+
progressPercent.value = Math.round((completedModels.value / totalModels.value) * 100);
1138+
}
11231139
);
11241140
1125-
// 处理测试结果
1126-
results.valid = testResults.valid;
1127-
results.invalid = testResults.invalid;
1128-
results.inconsistent = testResults.inconsistent;
1129-
results.awaitOfficialVerification = testResults.awaitOfficialVerification;
1130-
11311141
testModels_spinning.value = false;
11321142
1143+
// 所有模型测试完成后,显示摘要
11331144
showSummary(results);
1145+
11341146
} catch (error) {
11351147
testModels_spinning.value = false;
11361148
message.error('测试模型时发生错误: ' + error.message);
11371149
}
11381150
}
11391151
1152+
function updateTableData(progress) {
1153+
const { type, data } = progress;
1154+
1155+
// 根据类型,将结果添加到对应的数组
1156+
if (type === 'valid') {
1157+
results.valid.push(data);
1158+
} else if (type === 'invalid') {
1159+
results.invalid.push(data);
1160+
} else if (type === 'inconsistent') {
1161+
results.inconsistent.push(data);
1162+
}
1163+
1164+
// 重新计算表格数据
1165+
tableData.value = computeTableData();
1166+
1167+
// 更新进度
1168+
progressPercent.value = Math.round((completedModels.value / totalModels.value) * 100);
1169+
}
1170+
1171+
11401172
function showSummary(results) {
11411173
// 使用 reactive 的 'results' 对象
11421174
const resultsData = results;
@@ -1357,9 +1389,117 @@ const columns = [
13571389
];
13581390
13591391
// 定义 tableData
1360-
const tableData = computed(() => {
1392+
// const tableData = computed(() => {
1393+
// const data = [];
1394+
//
1395+
// results.valid.forEach((item, index) => {
1396+
// const buttons = [];
1397+
// buttons.push({
1398+
// label: t('FUNCTION_VERIFICATION'),
1399+
// type: 'default',
1400+
// onClick: () => verifyFunctionCalling(item.model),
1401+
// });
1402+
// if (isGpt(item.model) || isClaude(item.model)) {
1403+
// buttons.push({
1404+
// label: t('TEMPERATURE_VERIFICATION'),
1405+
// type: 'primary',
1406+
// onClick: () => verifyTemperature(item.model),
1407+
// });
1408+
// if (isGpt(item.model)) {
1409+
// const officialVerificationDone =
1410+
// results.awaitOfficialVerification &&
1411+
// results.awaitOfficialVerification.some((r) => r.model === item.model);
1412+
// const buttonType = officialVerificationDone ? 'success' : 'warning';
1413+
// buttons.push({
1414+
// label: t('OFFICIAL_VERIFICATION'),
1415+
// type: buttonType,
1416+
// onClick: () => verifyOfficial(item.model),
1417+
// });
1418+
// }
1419+
// }
1420+
// data.push({
1421+
// key: `valid-${index}`,
1422+
// status: t('MODEL_STATE_AVAILABLE'),
1423+
// model: item.model,
1424+
// responseTime: item.responseTime.toFixed(2),
1425+
// buttons: buttons,
1426+
// remark: '',
1427+
// });
1428+
// });
1429+
//
1430+
// results.inconsistent.forEach((item, index) => {
1431+
// const buttons = [];
1432+
// buttons.push({
1433+
// label: t('FUNCTION_VERIFICATION'),
1434+
// type: 'default',
1435+
// onClick: () => verifyFunctionCalling(item.model),
1436+
// });
1437+
// if (isGpt(item.model) || isClaude(item.model)) {
1438+
// buttons.push({
1439+
// label: t('TEMPERATURE_VERIFICATION'),
1440+
// type: 'primary',
1441+
// onClick: () => verifyTemperature(item.model),
1442+
// });
1443+
// if (isGpt(item.model)) {
1444+
// const officialVerificationDone =
1445+
// results.awaitOfficialVerification &&
1446+
// results.awaitOfficialVerification.some((r) => r.model === item.model);
1447+
// const buttonType = officialVerificationDone ? 'success' : 'warning';
1448+
// buttons.push({
1449+
// label: t('OFFICIAL_VERIFICATION'),
1450+
// type: buttonType,
1451+
// onClick: () => verifyOfficial(item.model),
1452+
// });
1453+
// }
1454+
// }
1455+
//
1456+
// // 根据返回的模型名称,判断是模型映射还是未匹配
1457+
// let status = '';
1458+
// let remark = '';
1459+
// let fullRemark = '';
1460+
//
1461+
// if (item.returnedModel && item.returnedModel.startsWith(`${item.model}-`)) {
1462+
// status = t('MODEL_STATE_INCONSISTENT');
1463+
// remark = '模型映射';
1464+
// fullRemark = `模型映射到:${item.returnedModel}`;
1465+
// } else {
1466+
// status = '🤔未匹配';
1467+
// remark = '未匹配';
1468+
// fullRemark = `返回模型:${item.returnedModel}`;
1469+
// }
1470+
//
1471+
// data.push({
1472+
// key: `inconsistent-${index}`,
1473+
// status: status,
1474+
// model: item.model,
1475+
// responseTime: item.responseTime.toFixed(2),
1476+
// buttons: buttons,
1477+
// remark: remark,
1478+
// fullRemark: fullRemark,
1479+
// });
1480+
// });
1481+
//
1482+
// results.invalid.forEach((item, index) => {
1483+
// let displayedRemark = '';
1484+
// let fullRemark = item.response_text || item.error || '';
1485+
// displayedRemark = errorHandler(fullRemark);
1486+
// data.push({
1487+
// key: `invalid-${index}`,
1488+
// status: t('MODEL_STATE_UNAVAILABLE'),
1489+
// model: item.model,
1490+
// responseTime: '-',
1491+
// buttons: [],
1492+
// remark: displayedRemark,
1493+
// fullRemark: fullRemark,
1494+
// });
1495+
// });
1496+
//
1497+
// return data;
1498+
// });
1499+
function computeTableData() {
13611500
const data = [];
13621501
1502+
// 处理 valid 模型
13631503
results.valid.forEach((item, index) => {
13641504
const buttons = [];
13651505
buttons.push({
@@ -1385,16 +1525,32 @@ const tableData = computed(() => {
13851525
});
13861526
}
13871527
}
1528+
1529+
// 针对 o1- 模型的特殊处理
1530+
let remark = '';
1531+
let fullRemark = '';
1532+
if (item.model.startsWith('o1-')) {
1533+
if (item.has_o1_reason) {
1534+
remark = '✨API 可靠';
1535+
fullRemark = '返回响应中包含非空 reasoning_tokens,API 可靠';
1536+
} else {
1537+
remark = '⚠️API 非官';
1538+
fullRemark = '返回响应中不包含 reasoning_tokens 或为空,API 非官';
1539+
}
1540+
}
1541+
13881542
data.push({
13891543
key: `valid-${index}`,
13901544
status: t('MODEL_STATE_AVAILABLE'),
13911545
model: item.model,
13921546
responseTime: item.responseTime.toFixed(2),
13931547
buttons: buttons,
1394-
remark: '',
1548+
remark: remark,
1549+
fullRemark: fullRemark,
13951550
});
13961551
});
13971552
1553+
// 处理 inconsistent 模型
13981554
results.inconsistent.forEach((item, index) => {
13991555
const buttons = [];
14001556
buttons.push({
@@ -1427,15 +1583,26 @@ const tableData = computed(() => {
14271583
let fullRemark = '';
14281584
14291585
if (item.returnedModel && item.returnedModel.startsWith(`${item.model}-`)) {
1430-
status = t('MODEL_STATE_INCONSISTENT');
1586+
status = `${t('MODEL_STATE_INCONSISTENT')} 🧐`;
14311587
remark = '模型映射';
14321588
fullRemark = `模型映射到:${item.returnedModel}`;
14331589
} else {
1434-
status = '🤔未匹配';
1590+
status = '🤔 未匹配';
14351591
remark = '未匹配';
14361592
fullRemark = `返回模型:${item.returnedModel}`;
14371593
}
14381594
1595+
// 针对 o1- 模型的特殊处理
1596+
if (item.model.startsWith('o1-')) {
1597+
if (item.has_o1_reason) {
1598+
remark += ' / ✨API 可靠';
1599+
fullRemark += ';返回响应中包含非空 reasoning_tokens,API 可靠';
1600+
} else {
1601+
remark += ' / ⚠️API 非官';
1602+
fullRemark += ';返回响应中不包含 reasoning_tokens 或为空,API 非官';
1603+
}
1604+
}
1605+
14391606
data.push({
14401607
key: `inconsistent-${index}`,
14411608
status: status,
@@ -1447,10 +1614,12 @@ const tableData = computed(() => {
14471614
});
14481615
});
14491616
1617+
// 处理 invalid 模型
14501618
results.invalid.forEach((item, index) => {
14511619
let displayedRemark = '';
14521620
let fullRemark = item.response_text || item.error || '';
14531621
displayedRemark = errorHandler(fullRemark);
1622+
14541623
data.push({
14551624
key: `invalid-${index}`,
14561625
status: t('MODEL_STATE_UNAVAILABLE'),
@@ -1463,8 +1632,7 @@ const tableData = computed(() => {
14631632
});
14641633
14651634
return data;
1466-
});
1467-
1635+
}
14681636
14691637
// 复制文本函数
14701638
function copyText(text) {
@@ -1685,13 +1853,13 @@ function openSettingsModal() {
16851853
fetchCloudData();
16861854
}
16871855
1688-
showSettingsModal1.value = true;
1856+
showAppSettingsModal.value = true;
16891857
}
16901858
16911859
16921860
// 关闭设置面板
16931861
function closeSettingsModal() {
1694-
showSettingsModal1.value = false;
1862+
showAppSettingsModal.value = false;
16951863
}
16961864
16971865
// 保存到本地缓存

0 commit comments

Comments
 (0)