模型配置个数修改,开始对话跳转修改

This commit is contained in:
2026-01-22 10:41:06 +08:00
parent 6c87af46ba
commit f126139bbd
2 changed files with 129 additions and 42 deletions

View File

@@ -499,8 +499,8 @@
return;
}
if (selectedModels.size < 2) {
showMessage('提示', '请至少选择2个模型进行对比', 'warning');
if (selectedModels.size < 1) {
showMessage('提示', '请至少选择1个模型进行对比', 'warning');
return;
}
@@ -521,8 +521,8 @@
const result = await response.json();
if (result.code === 0) {
showMessage('成功', '对比任务创建成功!', 'success', () => {
// 跳转到对比聊天页面
window.location.href = `model-compare-chat.html?id=${result.data?.id || ''}`;
// 跳转到模型对比列表页
window.location.href = 'main.html?page=model-compare';
});
} else {
showMessage('错误', result.message || '创建失败', 'error');

View File

@@ -81,7 +81,7 @@
resize: vertical;
min-height: 100px;
}
.radio-option {
.radio-option, .checkbox-option {
display: flex;
align-items: center;
padding: 0.75rem 1rem;
@@ -90,13 +90,16 @@
cursor: pointer;
transition: all 0.2s;
}
.radio-option:hover {
.radio-option:hover, .checkbox-option:hover {
border-color: #1890ff;
}
.radio-option.selected {
.radio-option.selected, .checkbox-option.selected {
border-color: #1890ff;
background-color: rgba(24, 144, 255, 0.05);
}
.checkbox-option input[type="checkbox"] {
display: none;
}
.radio-option input {
margin-right: 0.75rem;
}
@@ -315,6 +318,7 @@
<option value="">请选择指标类型</option>
<option value="classification">大模型评估-分类型</option>
<option value="metric">大模型评估-指标型</option>
<option value="text_similarity">规则评估-文本相似度</option>
</select>
</div>
<div>
@@ -329,7 +333,7 @@
<div id="evalConfigSection" style="display: none; margin-bottom: 1.5rem;">
<h3 class="text-sm font-semibold text-gray-700 mb-4 pb-2 border-b border-gray-100">计算配置</h3>
<div class="space-y-4">
<div>
<div id="evalModelSection">
<label class="form-label">选择大模型 <span class="text-red-500">*</span></label>
<select name="eval_model" id="evalModel" class="form-select">
<option value="">请选择评估使用的大模型</option>
@@ -342,11 +346,11 @@
</div>
<div>
<label class="form-label">评估方式 <span class="text-red-500">*</span></label>
<div class="grid grid-cols-3 gap-4" id="evalMethodContainer">
<div class="grid grid-cols-2 md:grid-cols-3 xl:grid-cols-5 gap-3" id="evalMethodContainer">
<!-- 评估方式将通过JS动态生成 -->
</div>
</div>
<div>
<div id="evalPromptSection">
<label class="form-label flex items-center">
评估 Prompt <span class="text-red-500 ml-1">*</span>
</label>
@@ -362,6 +366,33 @@
</div>
<p class="text-xs text-gray-400 mt-1">定义大模型评估时使用的提示词,支持 Markdown 语法</p>
</div>
<!-- 规则评估特有配置(仅文本相似度类型显示) -->
<div id="textSimilarityConfig" style="display: none;">
<div class="grid grid-cols-2 gap-4">
<div>
<label class="form-label">BLEU n-gram 范围</label>
<select name="bleu_n" class="form-select mt-1">
<option value="1-4">1-4 (标准)</option>
<option value="1-3">1-3</option>
<option value="1-2">1-2</option>
<option value="2-4">2-4</option>
<option value="3-4">3-4</option>
<option value="4-4">仅 4</option>
</select>
<p class="text-xs text-gray-400 mt-1">计算精度时使用的 N-gram 范围</p>
</div>
<div>
<label class="form-label">输出精度</label>
<select name="output_precision" class="form-select mt-1">
<option value="4">4 位小数 (0.0000)</option>
<option value="3" selected>3 位小数 (0.000)</option>
<option value="2">2 位小数 (0.00)</option>
<option value="1">1 位小数 (0.0)</option>
</select>
<p class="text-xs text-gray-400 mt-1">分数显示保留的小数位数</p>
</div>
</div>
</div>
<!-- 评分范围和通过阈值(仅指标型显示) -->
<div id="scoreConfigSection" style="display: none;">
<div class="mb-6">
@@ -444,10 +475,12 @@
const methods = EVAL_METHODS[type] || [];
const isMetric = type === 'metric';
const firstMethod = methods[0]?.value || 'standard';
// 规则评估不需要 Prompt
const isTextSimilarity = type === 'text_similarity';
container.innerHTML = methods.map((method, index) => `
<label class="radio-option ${index === 0 ? 'selected' : ''}" data-method="${method.value}">
<input type="radio" name="eval_method" value="${method.value}" ${index === 0 ? 'checked' : ''}>
<label class="checkbox-option ${index === 0 ? 'selected' : ''}" data-method="${method.value}">
<input type="checkbox" name="eval_method" value="${method.value}" ${index === 0 ? 'checked' : ''}>
<div>
<div class="font-medium text-gray-800">${method.name}</div>
<div class="text-xs text-gray-500">${method.desc}</div>
@@ -455,27 +488,36 @@
</label>
`).join('');
// 绑定评估方式radio点击事件
container.querySelectorAll('.radio-option').forEach(option => {
option.addEventListener('click', function() {
selectEvalMethod(this);
// 更新默认 Prompt
const method = this.dataset.method;
const promptEditor = document.getElementById('evalPromptEditor');
if (promptEditor && EVAL_METHOD_PROMPTS.hasOwnProperty(method)) {
promptEditor.innerText = EVAL_METHOD_PROMPTS[method];
updateMarkdownHighlight();
syncEditorContent();
// 绑定评估方式checkbox点击事件
container.querySelectorAll('.checkbox-option').forEach(option => {
option.addEventListener('click', function(e) {
const checkbox = this.querySelector('input[type="checkbox"]');
// 不手动切换状态,让浏览器自动处理,只更新样式
this.classList.toggle('selected', checkbox.checked);
// 更新默认 Prompt仅大模型评估需要
if (!isTextSimilarity) {
const selectedCheckbox = this.querySelector('input[type="checkbox"]:checked');
if (selectedCheckbox) {
const method = selectedCheckbox.value;
const promptEditor = document.getElementById('evalPromptEditor');
if (promptEditor && EVAL_METHOD_PROMPTS.hasOwnProperty(method)) {
promptEditor.innerText = EVAL_METHOD_PROMPTS[method];
updateMarkdownHighlight();
syncEditorContent();
}
}
}
});
});
// 初始化默认 Prompt
const promptEditor = document.getElementById('evalPromptEditor');
if (promptEditor && EVAL_METHOD_PROMPTS.hasOwnProperty(firstMethod)) {
promptEditor.innerText = EVAL_METHOD_PROMPTS[firstMethod];
updateMarkdownHighlight();
syncEditorContent();
// 初始化默认 Prompt(仅大模型评估需要)
if (!isTextSimilarity) {
const promptEditor = document.getElementById('evalPromptEditor');
if (promptEditor && EVAL_METHOD_PROMPTS.hasOwnProperty(firstMethod)) {
promptEditor.innerText = EVAL_METHOD_PROMPTS[firstMethod];
updateMarkdownHighlight();
syncEditorContent();
}
}
}
@@ -484,10 +526,32 @@
const type = document.getElementById('dimensionType').value;
const configSection = document.getElementById('evalConfigSection');
const scoreSection = document.getElementById('scoreConfigSection');
const evalModelSection = document.getElementById('evalModelSection');
const evalPromptSection = document.getElementById('evalPromptSection');
if (type === 'classification' || type === 'metric') {
configSection.style.display = 'block';
// 指标型才显示评分范围和通过阈值
scoreSection.style.display = (type === 'metric') ? 'block' : 'none';
// 显示评估模型和 Prompt
if (evalModelSection) evalModelSection.style.display = 'block';
if (evalPromptSection) evalPromptSection.style.display = 'block';
// 隐藏规则评估特有配置
const textSimConfig = document.getElementById('textSimilarityConfig');
if (textSimConfig) textSimConfig.style.display = 'none';
// 动态渲染评估方式
renderEvalMethods(type);
} else if (type === 'text_similarity') {
configSection.style.display = 'block';
// 规则评估不显示评分范围配置
scoreSection.style.display = 'none';
// 隐藏评估模型选择(规则评估不需要大模型)
if (evalModelSection) evalModelSection.style.display = 'none';
// 隐藏评估 Prompt规则评估不需要 Prompt
if (evalPromptSection) evalPromptSection.style.display = 'none';
// 显示规则评估特有配置
const textSimConfig = document.getElementById('textSimilarityConfig');
if (textSimConfig) textSimConfig.style.display = 'block';
// 动态渲染评估方式
renderEvalMethods(type);
} else {
@@ -495,19 +559,10 @@
}
}
// 选择评估方式
function selectEvalMethod(element) {
document.querySelectorAll('.radio-option').forEach(opt => {
opt.classList.remove('selected');
});
element.classList.add('selected');
element.querySelector('input').checked = true;
}
// 恢复默认评估 Prompt
function resetEvalPrompt() {
const promptEditor = document.getElementById('evalPromptEditor');
const selectedMethod = document.querySelector('.radio-option.selected input[name="eval_method"]');
const selectedMethod = document.querySelector('.checkbox-option.selected input[name="eval_method"]:checked, .radio-option.selected input[name="eval_method"]:checked');
const method = selectedMethod ? selectedMethod.value : 'standard';
if (promptEditor && EVAL_METHOD_PROMPTS.hasOwnProperty(method)) {
promptEditor.innerText = EVAL_METHOD_PROMPTS[method];
@@ -869,6 +924,13 @@
{ value: 'metric_standard', name: '综合评测', desc: '根据预设标准评分' },
{ value: 'semantic', name: '语义相似度', desc: '计算语义相似程度' },
{ value: 'custom', name: '自定义评分器', desc: '自定义评估规则' }
],
text_similarity: [
{ value: 'bleu_4', name: 'BLEU-4', desc: 'N-gram 精确度评估' },
{ value: 'cosine', name: 'Cosine', desc: '余弦相似度' },
{ value: 'rouge_1', name: 'ROUGE-1', desc: 'unigram 重叠评估' },
{ value: 'rouge_2', name: 'ROUGE-2', desc: 'bigram 重叠评估' },
{ value: 'rouge_4', name: 'ROUGE-4', desc: '4-gram 重叠评估' }
]
};
@@ -1038,20 +1100,45 @@
alert('请输入评估 Prompt');
return;
}
if (!evalMethod) {
alert('请选择评估方式');
return;
}
} else if (type === 'text_similarity') {
// 规则评估:获取所有选中的评估方式
const checkedMethods = Array.from(document.querySelectorAll('input[name="eval_method"]:checked')).map(cb => cb.value);
if (checkedMethods.length === 0) {
alert('请至少选择一个评估方式');
return;
}
}
// 获取评估方式(支持多选)
let evalMethod;
if (type === 'text_similarity') {
evalMethod = Array.from(document.querySelectorAll('input[name="eval_method"]:checked')).map(cb => cb.value);
} else {
evalMethod = formData.get('eval_method');
}
const data = {
name: name,
type: type,
description: formData.get('description').trim(),
eval_model: formData.get('eval_model'),
eval_method: formData.get('eval_method'),
eval_prompt: formData.get('eval_prompt').trim(),
eval_model: type === 'text_similarity' ? null : formData.get('eval_model'),
eval_method: evalMethod,
eval_prompt: type === 'text_similarity' ? null : formData.get('eval_prompt').trim(),
is_active: formData.get('is_active') === 'on',
is_default: formData.get('is_default') === 'on',
create_time: new Date().toLocaleString('zh-CN', { hour12: false }).replace(/\//g, '-')
};
// 规则评估特有配置
if (type === 'text_similarity') {
data.bleu_n = formData.get('bleu_n');
data.output_precision = parseInt(formData.get('output_precision') || '3');
}
// 指标型添加评分范围和通过阈值
if (type === 'metric') {
data.score_min = parseFloat(formData.get('score_min')) || 0;