This commit is contained in:
jack
2026-04-22 18:12:28 +08:00
parent 10953219f5
commit 14d2300564
11 changed files with 307 additions and 173 deletions
+47 -3
View File
@@ -45,6 +45,7 @@ const form = document.getElementById('transformerForm');
const submitBtn = document.getElementById('submitBtn');
const downloadBtn = document.getElementById('downloadBtn');
const loginAndFetchBtn = document.getElementById('loginAndFetchBtn');
const testLLMBtn = document.getElementById('testLLMBtn');
const regionSelect = document.getElementById('region');
const delaySelect = document.getElementById('delay');
const universeSelect = document.getElementById('universe');
@@ -105,6 +106,48 @@ loginAndFetchBtn.addEventListener('click', async () => {
}
});
testLLMBtn.addEventListener('click', async () => {
const apiKey = document.getElementById('llmApiKey').value.trim();
const baseUrl = document.getElementById('llmBaseUrl').value.trim();
const model = document.getElementById('llmModel').value.trim();
if (!apiKey || !baseUrl || !model) {
alert('请先填写完整的 LLM 配置');
return;
}
testLLMBtn.disabled = true;
testLLMBtn.textContent = '测试中...';
testLLMBtn.classList.remove('btn-success', 'btn-error');
try {
const response = await fetch('/api/test-llm', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
llm_api_key: apiKey,
llm_base_url: baseUrl,
llm_model: model
})
});
const result = await response.json();
if (result.success) {
testLLMBtn.textContent = '连接成功';
testLLMBtn.classList.add('btn-success');
} else {
testLLMBtn.textContent = '连接失败';
testLLMBtn.classList.add('btn-error');
}
} catch (error) {
testLLMBtn.textContent = '连接失败';
testLLMBtn.classList.add('btn-error');
} finally {
testLLMBtn.disabled = false;
}
});
function populateRegionSelect() {
while (regionSelect.options.length > 1) {
regionSelect.remove(1);
@@ -222,6 +265,7 @@ form.addEventListener('submit', async (e) => {
brain_username: document.getElementById('brainUsername').value.trim(),
brain_password: document.getElementById('brainPassword').value.trim(),
top_n_datafield: parseInt(document.getElementById('topNDatafield').value) || 50,
max_retries: parseInt(document.getElementById('maxRetries').value) || 20,
data_type: document.getElementById('dataType').value || 'MATRIX'
};
@@ -267,22 +311,22 @@ form.addEventListener('submit', async (e) => {
const successCount = result.expressions_success ? result.expressions_success.length : 0;
const candidateCount = result.candidates ? result.candidates.length : 0;
const errorCount = result.expressions_error ? result.expressions_error.length : 0;
alert('生成完成!成功: ' + successCount + ' 个, 候选: ' + candidateCount + ' 个, 错误: ' + errorCount + ' 个');
// 显示下载按钮
downloadBtn.style.display = 'block';
downloadBtn.textContent = '下载结果 (' + successCount + '成功, ' + candidateCount + '候选)';
downloadBtn.onclick = function() {
const alphaId = document.getElementById('alphaId').value.trim();
window.location.href = '/api/download/' + alphaId;
};
} else {
alert('生成失败: ' + (result.error || '未知错误'));
downloadBtn.style.display = 'none';
downloadBtn.textContent = '下载结果 (ZIP)';
}
} catch (error) {
alert('请求失败: ' + error.message);
downloadBtn.style.display = 'none';
downloadBtn.textContent = '下载结果 (ZIP)';
} finally {
submitBtn.disabled = false;
submitBtn.textContent = '生成变种';