1 .修改了新建评估指标删除的bug
This commit is contained in:
@@ -337,12 +337,8 @@
|
||||
<label class="form-label">选择大模型 <span class="text-red-500">*</span></label>
|
||||
<select name="eval_model" id="evalModel" class="form-select">
|
||||
<option value="">请选择评估使用的大模型</option>
|
||||
<option value="gpt-4">GPT-4</option>
|
||||
<option value="claude-3">Claude-3</option>
|
||||
<option value="ernie">文心一言</option>
|
||||
<option value="qwen">通义千问</option>
|
||||
<option value="chatglm">ChatGLM</option>
|
||||
</select>
|
||||
<p class="text-xs text-gray-400 mt-1">请在模型管理中配置"评测模型"用途的模型</p>
|
||||
</div>
|
||||
<div>
|
||||
<label class="form-label">评估方式 <span class="text-red-500">*</span></label>
|
||||
@@ -462,6 +458,35 @@
|
||||
};
|
||||
const API_BASE = getApiBase();
|
||||
|
||||
// 加载评测模型列表(用途为 evaluation 的模型)
|
||||
async function loadEvalModels() {
|
||||
try {
|
||||
const response = await fetch(`${API_BASE}/model-manage`);
|
||||
const result = await response.json();
|
||||
|
||||
if (result.code === 0 && result.data) {
|
||||
const evalModels = result.data.filter(m => m.purpose === 'evaluation');
|
||||
const select = document.getElementById('evalModel');
|
||||
|
||||
if (evalModels.length === 0) {
|
||||
select.innerHTML = '<option value="">暂无可用的评测模型</option>';
|
||||
return;
|
||||
}
|
||||
|
||||
select.innerHTML = '<option value="">请选择评估使用的大模型</option>';
|
||||
evalModels.forEach(model => {
|
||||
const option = document.createElement('option');
|
||||
option.value = model.id;
|
||||
option.textContent = `${model.name} (${model.model_source === 'api' ? 'API' : '本地'})`;
|
||||
select.appendChild(option);
|
||||
});
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('加载评测模型列表失败:', error);
|
||||
document.getElementById('evalModel').innerHTML = '<option value="">加载失败</option>';
|
||||
}
|
||||
}
|
||||
|
||||
// 返回列表页
|
||||
function goBack() {
|
||||
window.location.href = 'main.html?page=model-eval';
|
||||
@@ -935,13 +960,16 @@
|
||||
};
|
||||
|
||||
// 初始化函数
|
||||
function initPage() {
|
||||
async function initPage() {
|
||||
// 绑定指标类型下拉框事件
|
||||
const dimensionType = document.getElementById('dimensionType');
|
||||
if (dimensionType) {
|
||||
dimensionType.addEventListener('change', toggleEvalConfig);
|
||||
}
|
||||
|
||||
// 加载评测模型列表
|
||||
await loadEvalModels();
|
||||
|
||||
// 绑定 Markdown 编辑器事件
|
||||
const evalPromptEditor = document.getElementById('evalPromptEditor');
|
||||
if (evalPromptEditor) {
|
||||
@@ -1076,13 +1104,14 @@
|
||||
const name = formData.get('name').trim();
|
||||
const type = formData.get('type').trim();
|
||||
|
||||
// 验证
|
||||
if (!name) {
|
||||
alert('请输入维度名称');
|
||||
showMessage('提示', '请输入维度名称', 'warning');
|
||||
return;
|
||||
}
|
||||
|
||||
if (!type) {
|
||||
alert('请选择指标类型');
|
||||
showMessage('提示', '请选择指标类型', 'warning');
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -1093,22 +1122,22 @@
|
||||
const evalMethod = formData.get('eval_method');
|
||||
|
||||
if (!evalModel) {
|
||||
alert('请选择评估使用的大模型');
|
||||
showMessage('提示', '请选择评估使用的大模型', 'warning');
|
||||
return;
|
||||
}
|
||||
if (!evalPrompt) {
|
||||
alert('请输入评估 Prompt');
|
||||
showMessage('提示', '请输入评估 Prompt', 'warning');
|
||||
return;
|
||||
}
|
||||
if (!evalMethod) {
|
||||
alert('请选择评估方式');
|
||||
showMessage('提示', '请选择评估方式', 'warning');
|
||||
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('请至少选择一个评估方式');
|
||||
showMessage('提示', '请至少选择一个评估方式', 'warning');
|
||||
return;
|
||||
}
|
||||
}
|
||||
@@ -1147,22 +1176,92 @@
|
||||
}
|
||||
|
||||
try {
|
||||
const response = await fetch(`${API_BASE}/model-eval/dimension`, {
|
||||
const response = await fetch(`${API_BASE}/dimension`, {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify(data)
|
||||
});
|
||||
const result = await response.json();
|
||||
if (result.code === 0) {
|
||||
alert('评测维度创建成功!');
|
||||
goBack();
|
||||
showMessage('成功', '评测维度创建成功!', 'success', () => {
|
||||
goBack();
|
||||
});
|
||||
} else {
|
||||
alert('创建失败: ' + (result.message || '未知错误'));
|
||||
showMessage('错误', result.message || '创建失败', 'error');
|
||||
}
|
||||
} catch (error) {
|
||||
alert('创建失败: ' + error.message);
|
||||
showMessage('错误', '创建失败: ' + error.message, 'error');
|
||||
}
|
||||
}
|
||||
|
||||
// ============ 自定义消息弹窗 ============
|
||||
function showMessage(title, message, type = 'info', onConfirm) {
|
||||
const modal = document.getElementById('customModal');
|
||||
const modalTitle = document.getElementById('modalTitle');
|
||||
const modalMessage = document.getElementById('modalMessage');
|
||||
const modalIcon = document.getElementById('modalIcon');
|
||||
const modalConfirmBtn = document.getElementById('modalConfirmBtn2');
|
||||
const modalBtnGroup = document.getElementById('modalBtnGroup');
|
||||
const modalSingleBtnGroup = document.getElementById('modalSingleBtnGroup');
|
||||
|
||||
if (!modalConfirmBtn) {
|
||||
console.error('modalConfirmBtn2 not found');
|
||||
return;
|
||||
}
|
||||
|
||||
modalTitle.textContent = title;
|
||||
modalMessage.innerHTML = message;
|
||||
|
||||
if (type === 'success') {
|
||||
modalIcon.innerHTML = '<div class="w-12 h-12 mx-auto mb-4 rounded-full bg-green-100 flex items-center justify-center"><i class="fa fa-check text-xl text-green-600"></i></div>';
|
||||
} else if (type === 'error') {
|
||||
modalIcon.innerHTML = '<div class="w-12 h-12 mx-auto mb-4 rounded-full bg-red-100 flex items-center justify-center"><i class="fa fa-times text-xl text-red-600"></i></div>';
|
||||
} else if (type === 'warning') {
|
||||
modalIcon.innerHTML = '<div class="w-12 h-12 mx-auto mb-4 rounded-full bg-yellow-100 flex items-center justify-center"><i class="fa fa-exclamation text-xl text-yellow-600"></i></div>';
|
||||
} else {
|
||||
modalIcon.innerHTML = '<div class="w-12 h-12 mx-auto mb-4 rounded-full bg-blue-100 flex items-center justify-center"><i class="fa fa-info text-xl text-blue-600"></i></div>';
|
||||
}
|
||||
|
||||
// 隐藏双按钮组,显示单按钮组
|
||||
if (modalBtnGroup) modalBtnGroup.classList.add('hidden');
|
||||
modalSingleBtnGroup.classList.remove('hidden');
|
||||
modalConfirmBtn.className = type === 'error' ? 'px-6 py-2 bg-red-500 text-white rounded-lg hover:bg-red-600 transition-colors' : 'px-6 py-2 bg-primary text-white rounded-lg hover:bg-primary/90 transition-colors';
|
||||
|
||||
modal.classList.remove('hidden');
|
||||
document.body.style.overflow = 'hidden';
|
||||
|
||||
// 保存回调到按钮属性
|
||||
modalConfirmBtn._onConfirm = onConfirm;
|
||||
|
||||
// 使用 function 确保 this 指向正确
|
||||
modalConfirmBtn.onclick = function() {
|
||||
modal.classList.add('hidden');
|
||||
document.body.style.overflow = '';
|
||||
const callback = this._onConfirm;
|
||||
if (typeof callback === 'function') {
|
||||
callback();
|
||||
}
|
||||
this._onConfirm = null;
|
||||
};
|
||||
}
|
||||
</script>
|
||||
|
||||
<!-- 自定义消息弹窗 -->
|
||||
<div id="customModal" class="hidden fixed inset-0 bg-black/50 z-50 flex items-center justify-center">
|
||||
<div class="bg-white rounded-xl shadow-xl max-w-md w-full mx-4 overflow-hidden">
|
||||
<div class="p-6 text-center">
|
||||
<div id="modalIcon"></div>
|
||||
<h3 id="modalTitle" class="text-lg font-medium text-gray-800 mb-2"></h3>
|
||||
<p id="modalMessage" class="text-gray-600 text-sm"></p>
|
||||
</div>
|
||||
<div id="modalBtnGroup" class="hidden px-6 pb-6 flex justify-center space-x-4">
|
||||
<button id="modalCancelBtn" class="px-6 py-2 bg-gray-200 text-gray-700 rounded-lg hover:bg-gray-300 transition-colors">取消</button>
|
||||
<button id="modalConfirmBtn" class="px-6 py-2 bg-primary text-white rounded-lg hover:bg-primary/90 transition-colors">确定</button>
|
||||
</div>
|
||||
<div id="modalSingleBtnGroup" class="px-6 pb-6 flex justify-center">
|
||||
<button id="modalConfirmBtn2" class="px-6 py-2 text-white rounded-lg transition-colors">确定</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
Reference in New Issue
Block a user