1. 增加了模型管理页面的功能
2. 修改了若干的bug
This commit is contained in:
@@ -178,8 +178,7 @@
|
||||
<span class="text-red-500 mr-1">*</span>模型类型
|
||||
</label>
|
||||
<select name="type" class="form-input">
|
||||
<option value="">请选择</option>
|
||||
<option value="LLM">大语言模型 (LLM)</option>
|
||||
<option value="LLM" selected>大语言模型 (LLM)</option>
|
||||
<option value="CV">计算机视觉 (CV)</option>
|
||||
<option value="NLP">自然语言处理 (NLP)</option>
|
||||
<option value="Embedding">向量模型 (Embedding)</option>
|
||||
@@ -189,25 +188,11 @@
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- 版本信息 -->
|
||||
<div class="mb-6">
|
||||
<h3 class="text-sm font-semibold text-gray-700 mb-4 pb-2 border-b border-gray-100">版本信息</h3>
|
||||
<div class="max-w-md">
|
||||
<label class="form-label">
|
||||
<span class="text-red-500 mr-1">*</span>模型版本
|
||||
</label>
|
||||
<input type="text" name="version" class="form-input" placeholder="如:v1.0.0" maxlength="50">
|
||||
<p class="text-xs text-gray-400 mt-1">建议使用语义化版本号,如:v1.0.0、v2.1.0</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- 模型路径 -->
|
||||
<div class="mb-6">
|
||||
<h3 class="text-sm font-semibold text-gray-700 mb-4 pb-2 border-b border-gray-100">模型路径</h3>
|
||||
<h3 class="text-sm font-semibold text-gray-700 mb-4 pb-2 border-b border-gray-100">模型来源</h3>
|
||||
|
||||
<!-- 模型来源选择 -->
|
||||
<div class="mb-4">
|
||||
<label class="block text-sm text-gray-600 mb-3">模型来源</label>
|
||||
<div class="flex items-center space-x-6">
|
||||
<label class="flex items-center cursor-pointer">
|
||||
<input type="radio" name="model_source" value="local" checked class="mr-2" onchange="toggleModelSource('local')">
|
||||
@@ -291,18 +276,42 @@
|
||||
// 返回页面
|
||||
let backUrl = 'main.html?page=model-manage';
|
||||
|
||||
// 编辑模式
|
||||
let isEditMode = false;
|
||||
let editId = null;
|
||||
|
||||
// 页面加载完成后初始化
|
||||
document.addEventListener('DOMContentLoaded', function() {
|
||||
// 根据URL参数设置返回页面
|
||||
const urlParams = new URLSearchParams(window.location.search);
|
||||
const from = urlParams.get('from');
|
||||
const id = urlParams.get('id');
|
||||
const breadcrumbParent = document.getElementById('breadcrumbParent');
|
||||
|
||||
if (from === 'fine-tune') {
|
||||
backUrl = 'fine-tune-create.html';
|
||||
if (breadcrumbParent) {
|
||||
breadcrumbParent.textContent = '创建训练任务';
|
||||
}
|
||||
}
|
||||
|
||||
// 编辑模式
|
||||
if (id) {
|
||||
isEditMode = true;
|
||||
editId = parseInt(id);
|
||||
// 修改标题
|
||||
if (breadcrumbParent) {
|
||||
breadcrumbParent.textContent = '模型管理';
|
||||
}
|
||||
// 修改按钮文字
|
||||
const saveBtn = document.querySelector('button[onclick="submitForm()"]');
|
||||
if (saveBtn) {
|
||||
saveBtn.innerHTML = '<i class="fa fa-check mr-2"></i>保存修改';
|
||||
}
|
||||
// 加载模型数据
|
||||
loadModelData(editId);
|
||||
}
|
||||
|
||||
// 描述字数统计
|
||||
const descInput = document.querySelector('textarea[name="description"]');
|
||||
if (descInput) {
|
||||
@@ -322,6 +331,45 @@
|
||||
});
|
||||
});
|
||||
|
||||
// 加载模型数据(编辑模式)
|
||||
async function loadModelData(id) {
|
||||
try {
|
||||
const response = await fetch(`${API_BASE}/model-manage/${id}`);
|
||||
const result = await response.json();
|
||||
if (result.code === 0 && result.data) {
|
||||
const model = result.data;
|
||||
// 填充表单
|
||||
document.querySelector('input[name="name"]').value = model.name || '';
|
||||
document.querySelector('select[name="type"]').value = model.type || 'LLM';
|
||||
|
||||
// 设置模型来源
|
||||
const modelSource = model.model_source || 'local';
|
||||
document.querySelectorAll('input[name="model_source"]').forEach(radio => {
|
||||
radio.checked = radio.value === modelSource;
|
||||
});
|
||||
|
||||
// 根据来源显示对应面板
|
||||
toggleModelSource(modelSource);
|
||||
|
||||
// 填充来源相关字段
|
||||
if (modelSource === 'local') {
|
||||
document.querySelector('input[name="local_path"]').value = model.path || '';
|
||||
} else {
|
||||
document.querySelector('input[name="api_url"]').value = model.api_url || '';
|
||||
document.querySelector('input[name="api_key"]').value = model.api_key || '';
|
||||
document.querySelector('input[name="online_model_name"]').value = model.model_name || '';
|
||||
}
|
||||
|
||||
// 填充描述
|
||||
const descInput = document.querySelector('textarea[name="description"]');
|
||||
descInput.value = model.description || '';
|
||||
document.getElementById('descCount').textContent = descInput.value.length;
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('加载模型数据失败:', error);
|
||||
}
|
||||
}
|
||||
|
||||
// 切换模型来源
|
||||
function toggleModelSource(source) {
|
||||
const localPanel = document.getElementById('localModelPanel');
|
||||
@@ -337,14 +385,15 @@
|
||||
|
||||
// 提交表单
|
||||
async function submitForm() {
|
||||
console.log('submitForm called');
|
||||
const form = document.getElementById('modelForm');
|
||||
const formData = new FormData(form);
|
||||
const modelSource = formData.get('model_source');
|
||||
console.log('modelSource:', modelSource);
|
||||
|
||||
const data = {
|
||||
name: formData.get('name'),
|
||||
type: formData.get('type'),
|
||||
version: formData.get('version'),
|
||||
model_source: modelSource,
|
||||
description: formData.get('description')
|
||||
};
|
||||
@@ -383,27 +432,37 @@
|
||||
showMessage('提示', '请选择模型类型', 'warning');
|
||||
return;
|
||||
}
|
||||
if (!data.version) {
|
||||
showMessage('提示', '请输入模型版本', 'warning');
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
const response = await fetch(`${API_BASE}/model-manage`, {
|
||||
method: 'POST',
|
||||
let url = `${API_BASE}/model-manage`;
|
||||
let method = 'POST';
|
||||
let successMsg = '模型添加成功!';
|
||||
|
||||
if (isEditMode) {
|
||||
url = `${API_BASE}/model-manage/${editId}`;
|
||||
method = 'PUT';
|
||||
successMsg = '模型修改成功!';
|
||||
}
|
||||
|
||||
console.log('Sending request to:', url);
|
||||
console.log('Request data:', data);
|
||||
const response = await fetch(url, {
|
||||
method: method,
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify(data)
|
||||
});
|
||||
console.log('Response status:', response.status);
|
||||
const result = await response.json();
|
||||
console.log('Response data:', result);
|
||||
if (result.code === 0) {
|
||||
showMessage('成功', '模型添加成功!', 'success', () => {
|
||||
showMessage('成功', successMsg, 'success', () => {
|
||||
window.location.href = 'main.html?page=model-manage';
|
||||
});
|
||||
} else {
|
||||
showMessage('错误', result.message || '添加失败', 'error');
|
||||
showMessage('错误', result.message || '操作失败', 'error');
|
||||
}
|
||||
} catch (error) {
|
||||
showMessage('错误', '添加失败: ' + error.message, 'error');
|
||||
showMessage('错误', '操作失败: ' + error.message, 'error');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -414,7 +473,6 @@
|
||||
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');
|
||||
|
||||
modalTitle.textContent = title;
|
||||
@@ -430,7 +488,6 @@
|
||||
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>';
|
||||
}
|
||||
|
||||
modalBtnGroup.classList.add('hidden');
|
||||
modalSingleBtnGroup.classList.remove('hidden');
|
||||
modalConfirmBtn.className = type === 'error' ? 'px-6 py-2 bg-danger text-white rounded-lg hover:bg-danger/90 transition-colors' : 'px-6 py-2 bg-primary text-white rounded-lg hover:bg-primary/90 transition-colors';
|
||||
|
||||
|
||||
Reference in New Issue
Block a user