提交 cdc562e6 authored 作者: yujiejie's avatar yujiejie

验收台3.0

上级 9c0b03b9
...@@ -1741,6 +1741,173 @@ function runMentorDeployChatTest() { ...@@ -1741,6 +1741,173 @@ function runMentorDeployChatTest() {
}); });
} }
// ===== 导师部署验收台:真实 API 测试(图像生成)=====
function getMentorDeployGenSubmitUrl() {
var p = getMentorDeployReviewParams(Number(mentorState.deployReviewStudentId));
return joinMentorDeployPath(getMentorDeployBaseUrl(), p.apiPath || '/v1/generations');
}
function getMentorDeployGenStatusUrl() {
var sid = Number(mentorState.deployReviewStudentId);
var tests = mentorDeployReviewState.tests[sid] || {};
var taskId = (tests.genSubmit && tests.genSubmit.taskId) || '';
var base = getMentorDeployBaseUrl();
return taskId ? (base + '/v1/generations/' + encodeURIComponent(taskId)) : (base ? base + '/v1/generations/{id}' : '');
}
function mentorDeployPickTaskInfo(data) {
var root = (data && data.data && !data.id) ? data.data : data;
if (!root) return { id: '', status: '', progress: 0, outputs: [] };
return {
id: root.id || '',
status: root.status || '',
progress: root.progress || 0,
outputs: Array.isArray(root.outputs) ? root.outputs : []
};
}
function runMentorDeployGenSubmitTest() {
var sid = Number(mentorState.deployReviewStudentId);
var p = getMentorDeployReviewParams(sid);
var base = getMentorDeployBaseUrl();
if (!base) {
showStudentFlowModal('缺少 API 地址', '请在验收参数中填写 API 地址后再测试。');
return;
}
if (!mentorDeployReviewState.tests[sid]) mentorDeployReviewState.tests[sid] = {};
var url = getMentorDeployGenSubmitUrl();
var startedAt = Date.now();
mentorDeployReviewState.tests[sid].genSubmit = { status: 'loading', url: url };
renderContent();
var body = {
model: p.modelName || '',
modality: 'image',
prompt: p.imagePrompt || '',
inputs: []
};
body.options = { size: p.size || '1024x1024' };
var seed = parseInt(p.seed, 10);
if (!isNaN(seed)) body.options.seed = seed;
fetch(url, {
method: 'POST',
headers: getMentorDeployRequestHeaders(),
body: JSON.stringify(body)
})
.then(function(res) {
return res.text().then(function(text) {
var latency = Date.now() - startedAt;
var data = null;
var raw = text;
try { data = JSON.parse(text); raw = JSON.stringify(data, null, 2); } catch (e) { data = null; }
var info = mentorDeployPickTaskInfo(data);
var httpOk = res.status >= 200 && res.status < 300;
var pass = httpOk && !!info.id;
var err = '';
if (!httpOk) {
err = '接口返回非 2xx:HTTP ' + res.status + (data && data.error && data.error.message ? ' · ' + data.error.message : '');
} else if (!info.id) {
err = 'HTTP ' + res.status + ',但未解析到任务 ID(data.id),请确认返回结构与 API 文档一致。';
}
mentorDeployReviewState.tests[sid].genSubmit = {
status: pass ? 'pass' : 'fail',
httpStatus: res.status,
latency: latency,
taskId: info.id,
raw: raw,
error: err,
testedAt: getMentorDeployNowTimestamp(),
url: url
};
if (currentPage === 'mentor-deploy-review') renderContent();
});
})
.catch(function(err) {
var latency = Date.now() - startedAt;
mentorDeployReviewState.tests[sid].genSubmit = {
status: 'fail',
httpStatus: 0,
latency: latency,
taskId: '',
raw: null,
error: '网络请求失败:' + (err && err.message ? err.message : String(err)) + '。如果被 CORS 跨域拦截,请确认服务端已允许跨域后再测试。',
testedAt: getMentorDeployNowTimestamp(),
url: url
};
if (currentPage === 'mentor-deploy-review') renderContent();
});
}
function runMentorDeployGenStatusTest() {
var sid = Number(mentorState.deployReviewStudentId);
var p = getMentorDeployReviewParams(sid);
var base = getMentorDeployBaseUrl();
if (!base) {
showStudentFlowModal('缺少 API 地址', '请在验收参数中填写 API 地址后再测试。');
return;
}
var tests = mentorDeployReviewState.tests[sid] || {};
var prevTaskId = (tests.genSubmit && tests.genSubmit.taskId) || '';
if (!prevTaskId) {
showStudentFlowModal('无任务 ID', '请先提交生成任务,获得任务 ID 后再查询状态。');
return;
}
if (!mentorDeployReviewState.tests[sid]) mentorDeployReviewState.tests[sid] = {};
var url = base + '/v1/generations/' + encodeURIComponent(prevTaskId);
var startedAt = Date.now();
mentorDeployReviewState.tests[sid].genStatus = { status: 'loading', url: url, taskId: prevTaskId };
renderContent();
fetch(url, { method: 'GET', headers: getMentorDeployRequestHeaders() })
.then(function(res) {
return res.text().then(function(text) {
var latency = Date.now() - startedAt;
var data = null;
var raw = text;
try { data = JSON.parse(text); raw = JSON.stringify(data, null, 2); } catch (e) { data = null; }
var info = mentorDeployPickTaskInfo(data);
var httpOk = res.status >= 200 && res.status < 300;
var pass = httpOk && info.status === 'succeeded' && info.outputs.length > 0;
var err = '';
if (!httpOk) {
err = '接口返回非 2xx:HTTP ' + res.status + (data && data.error && data.error.message ? ' · ' + data.error.message : '');
} else if (info.status === 'failed') {
err = '生成任务失败,状态:' + info.status + '。' + (data && data.error ? '错误:' + JSON.stringify(data.error) : '');
}
mentorDeployReviewState.tests[sid].genStatus = {
status: pass ? 'pass' : 'fail',
httpStatus: res.status,
latency: latency,
taskId: prevTaskId,
taskStatus: info.status,
progress: info.progress,
outputs: info.outputs,
raw: raw,
error: err,
testedAt: getMentorDeployNowTimestamp(),
url: url
};
if (currentPage === 'mentor-deploy-review') renderContent();
});
})
.catch(function(err) {
var latency = Date.now() - startedAt;
mentorDeployReviewState.tests[sid].genStatus = {
status: 'fail',
httpStatus: 0,
latency: latency,
taskId: prevTaskId,
taskStatus: '',
progress: 0,
outputs: [],
raw: null,
error: '网络请求失败:' + (err && err.message ? err.message : String(err)) + '。如果被 CORS 跨域拦截,请确认服务端已允许跨域后再测试。',
testedAt: getMentorDeployNowTimestamp(),
url: url
};
if (currentPage === 'mentor-deploy-review') renderContent();
});
}
function mentorDeployTestNotReady(name) { function mentorDeployTestNotReady(name) {
showStudentFlowModal('测试功能待接入', '「' + name + '」的 API 测试将在下一步接入,当前为验收台静态布局预览。'); showStudentFlowModal('测试功能待接入', '「' + name + '」的 API 测试将在下一步接入,当前为验收台静态布局预览。');
} }
...@@ -1860,16 +2027,21 @@ function buildMentorDeployImageGenItems(sid) { ...@@ -1860,16 +2027,21 @@ function buildMentorDeployImageGenItems(sid) {
var modelsResult = tests.models || null; var modelsResult = tests.models || null;
var genResult = tests.genSubmit || null; var genResult = tests.genSubmit || null;
var statusResult = tests.genStatus || null; var statusResult = tests.genStatus || null;
var modelsLoading = !!(modelsResult && modelsResult.status === 'loading');
var genLoading = !!(genResult && genResult.status === 'loading');
var statusLoading = !!(statusResult && statusResult.status === 'loading');
return '<div class="bg-white rounded-lg border border-[#E5E6EB] p-4 mb-4">' + return '<div class="bg-white rounded-lg border border-[#E5E6EB] p-4 mb-4">' +
'<div class="flex items-center justify-between mb-3"><h3 class="font-semibold text-[#1D2129]">图像生成验收项</h3><span class="text-xs px-2 py-1 rounded bg-[#F2F3F5] text-[#86909C]">' + buildMentorDeployTestSummary(tests, ['models', 'genSubmit', 'genStatus']) + '</span></div>' + '<div class="flex items-center justify-between mb-3"><h3 class="font-semibold text-[#1D2129]">图像生成验收项</h3><span class="text-xs px-2 py-1 rounded bg-[#F2F3F5] text-[#86909C]">' + buildMentorDeployTestSummary(tests, ['models', 'genSubmit', 'genStatus']) + '</span></div>' +
'<div class="p-3 rounded-lg bg-[#F7F8FA] mb-3">' + '<div class="p-3 rounded-lg bg-[#F7F8FA] mb-3">' +
buildMentorDeployTestItemHeader('GET', '/v1/models', '图像模型列表', modelsResult) + buildMentorDeployTestItemHeader('GET', '/v1/models', '图像模型列表', modelsResult) +
'<div class="mt-2 text-xs font-mono text-[#4E5969] bg-white border border-[#E5E6EB] rounded p-2 break-all">' + mentorDeployReviewEsc(getMentorDeployModelsUrl()) + '</div>' +
buildMentorDeployTestMeta(modelsResult) + buildMentorDeployTestMeta(modelsResult) +
buildMentorDeployTestError(modelsResult) + buildMentorDeployTestError(modelsResult) +
'<button class="btn-outline w-full mt-3 py-2 text-sm" onclick="mentorDeployTestNotReady(\'图像模型列表\')">测试</button>' + '<button class="btn-outline w-full mt-3 py-2 text-sm" onclick="runMentorDeployModelsTest()" ' + (modelsLoading ? ' disabled' : '') + '>' + (modelsLoading ? '测试中…' : '测试') + '</button>' +
'</div>' + '</div>' +
'<div class="p-3 rounded-lg bg-[#F7F8FA] mb-3">' + '<div class="p-3 rounded-lg bg-[#F7F8FA] mb-3">' +
buildMentorDeployTestItemHeader('POST', '/v1/generations', '提交生成任务', genResult) + buildMentorDeployTestItemHeader('POST', '/v1/generations', '提交生成任务', genResult) +
'<div class="mt-2 text-xs font-mono text-[#4E5969] bg-white border border-[#E5E6EB] rounded p-2 break-all">' + mentorDeployReviewEsc(getMentorDeployGenSubmitUrl()) + '</div>' +
'<div class="mt-2"><label class="text-xs font-medium text-[#4E5969] block mb-1">生成描述</label><textarea class="input-field text-sm min-h-[64px] resize-none" oninput="setMentorDeployReviewParam(\'imagePrompt\', this.value)">' + mentorDeployReviewEsc(p.imagePrompt) + '</textarea></div>' + '<div class="mt-2"><label class="text-xs font-medium text-[#4E5969] block mb-1">生成描述</label><textarea class="input-field text-sm min-h-[64px] resize-none" oninput="setMentorDeployReviewParam(\'imagePrompt\', this.value)">' + mentorDeployReviewEsc(p.imagePrompt) + '</textarea></div>' +
'<div class="grid grid-cols-2 gap-2 mt-2">' + '<div class="grid grid-cols-2 gap-2 mt-2">' +
'<div><label class="text-xs font-medium text-[#4E5969] block mb-1">图片尺寸</label><select class="input-field text-sm" onchange="setMentorDeployReviewParam(\'size\', this.value)">' + getMentorDeploySizeOptions(p.size) + '</select></div>' + '<div><label class="text-xs font-medium text-[#4E5969] block mb-1">图片尺寸</label><select class="input-field text-sm" onchange="setMentorDeployReviewParam(\'size\', this.value)">' + getMentorDeploySizeOptions(p.size) + '</select></div>' +
...@@ -1878,16 +2050,17 @@ function buildMentorDeployImageGenItems(sid) { ...@@ -1878,16 +2050,17 @@ function buildMentorDeployImageGenItems(sid) {
buildMentorDeployTestMeta(genResult) + buildMentorDeployTestMeta(genResult) +
(genResult && genResult.taskId ? '<div class="mt-1.5 text-xs text-[#4E5969]">任务 ID:<b class="font-mono">' + mentorDeployReviewEsc(genResult.taskId) + '</b></div>' : '') + (genResult && genResult.taskId ? '<div class="mt-1.5 text-xs text-[#4E5969]">任务 ID:<b class="font-mono">' + mentorDeployReviewEsc(genResult.taskId) + '</b></div>' : '') +
buildMentorDeployTestError(genResult) + buildMentorDeployTestError(genResult) +
'<button class="btn-primary w-full mt-3 py-2 text-sm" onclick="mentorDeployTestNotReady(\'提交生成任务\')">提交生成任务</button>' + '<button class="btn-primary w-full mt-3 py-2 text-sm" onclick="runMentorDeployGenSubmitTest()" ' + (genLoading ? ' disabled' : '') + '>' + (genLoading ? '提交中…' : '提交生成任务') + '</button>' +
'</div>' + '</div>' +
'<div class="p-3 rounded-lg bg-[#F7F8FA]">' + '<div class="p-3 rounded-lg bg-[#F7F8FA]">' +
buildMentorDeployTestItemHeader('GET', '/v1/generations/{id}', '查询生成任务', statusResult) + buildMentorDeployTestItemHeader('GET', '/v1/generations/{id}', '查询生成任务', statusResult) +
'<div class="mt-2 text-xs font-mono text-[#4E5969] bg-white border border-[#E5E6EB] rounded p-2 break-all">' + mentorDeployReviewEsc(getMentorDeployGenStatusUrl()) + '</div>' +
buildMentorDeployTestMeta(statusResult) + buildMentorDeployTestMeta(statusResult) +
(statusResult && statusResult.taskStatus (statusResult && statusResult.taskStatus
? '<div class="mt-1.5 text-xs text-[#4E5969]">任务状态:<b class="' + (statusResult.taskStatus === 'succeeded' ? 'text-emerald-600' : 'text-[#1D2129]') + '">' + mentorDeployReviewEsc(statusResult.taskStatus) + '</b> · 进度:' + (statusResult.progress || 0) + '%</div>' ? '<div class="mt-1.5 text-xs text-[#4E5969]">任务状态:<b class="' + (statusResult.taskStatus === 'succeeded' ? 'text-emerald-600' : 'text-[#1D2129]') + '">' + mentorDeployReviewEsc(statusResult.taskStatus) + '</b> · 进度:' + (statusResult.progress || 0) + '%</div>'
: '') + : '') +
buildMentorDeployTestError(statusResult) + buildMentorDeployTestError(statusResult) +
'<button class="btn-outline w-full mt-3 py-2 text-sm" onclick="mentorDeployTestNotReady(\'查询生成任务\')">查询状态</button>' + '<button class="btn-outline w-full mt-3 py-2 text-sm" onclick="runMentorDeployGenStatusTest()" ' + (statusLoading ? ' disabled' : '') + '>' + (statusLoading ? '查询中…' : '查询状态') + '</button>' +
'</div>' + '</div>' +
'</div>'; '</div>';
} }
......
Markdown 格式
0% 或
您添加了 0 人 到此讨论。请谨慎行事。
请先完成此评论的编辑!
请 注册 或者 后发表评论