1. 增加了本地模型的检测接口
This commit is contained in:
@@ -155,3 +155,37 @@ def delete_model_manage(id):
|
||||
"""删除模型"""
|
||||
generic_delete('model_manage', id)
|
||||
return jsonify({'code': 0, 'message': '删除成功'})
|
||||
|
||||
|
||||
# ============ 本地模型列表接口 ============
|
||||
|
||||
@model_manage_bp.route('/local-models', methods=['GET'])
|
||||
def get_local_models():
|
||||
"""获取本地模型列表(从YG_FT_Base/local_models目录)"""
|
||||
import logging
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
try:
|
||||
# 使用 YG_FT_Base/local_models 目录
|
||||
base_path = os.path.join(PROJECT_ROOT, 'local_models')
|
||||
|
||||
models = []
|
||||
if os.path.exists(base_path):
|
||||
for item in os.listdir(base_path):
|
||||
item_path = os.path.join(base_path, item)
|
||||
if os.path.isdir(item_path):
|
||||
models.append({
|
||||
'name': item,
|
||||
'path': item_path
|
||||
})
|
||||
|
||||
return jsonify({
|
||||
'code': 0,
|
||||
'data': {
|
||||
'models': models,
|
||||
'base_path': base_path
|
||||
}
|
||||
})
|
||||
except Exception as e:
|
||||
logger.error(f"获取本地模型列表失败: {e}")
|
||||
return jsonify({'code': 1, 'message': str(e)})
|
||||
|
||||
@@ -275,8 +275,9 @@
|
||||
<label class="form-label">
|
||||
<span class="text-red-500 mr-1">*</span>模型加载路径
|
||||
</label>
|
||||
<input type="text" name="local_path" class="form-input" placeholder="如:/models/my-model 或 s3://bucket/models/my-model">
|
||||
<p class="text-xs text-gray-400 mt-1">支持本地路径或云存储路径(OSS、S3、HDFS等)</p>
|
||||
<select name="local_path" id="localModelSelect" class="form-select">
|
||||
<option value="">-- 选择本地模型 --</option>
|
||||
</select>
|
||||
</div>
|
||||
|
||||
<!-- 在线模型配置 -->
|
||||
@@ -395,6 +396,12 @@
|
||||
});
|
||||
});
|
||||
|
||||
// 如果默认选中本地模型,立即加载模型列表
|
||||
const localRadio = document.querySelector('input[name="model_source"][value="local"]');
|
||||
if (localRadio && localRadio.checked) {
|
||||
loadLocalModels();
|
||||
}
|
||||
|
||||
// 设置侧边栏当前页高亮
|
||||
const currentPage = 'model-manage';
|
||||
document.querySelectorAll('.nav-link').forEach(link => {
|
||||
@@ -445,7 +452,22 @@
|
||||
|
||||
// 填充来源相关字段
|
||||
if (modelSource === 'local') {
|
||||
document.querySelector('input[name="local_path"]').value = model.path || '';
|
||||
const path = model.path || '';
|
||||
// 尝试在选择器中找到匹配的模型
|
||||
loadLocalModels().then(() => {
|
||||
const select = document.getElementById('localModelSelect');
|
||||
if (select && path) {
|
||||
// 尝试精确匹配或部分匹配
|
||||
for (let i = 0; i < select.options.length; i++) {
|
||||
if (select.options[i].value === path ||
|
||||
select.options[i].textContent === path ||
|
||||
path.includes(select.options[i].textContent)) {
|
||||
select.selectedIndex = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
} else {
|
||||
document.querySelector('input[name="api_url"]').value = model.api_url || '';
|
||||
document.querySelector('input[name="api_key"]').value = model.api_key || '';
|
||||
@@ -475,6 +497,8 @@
|
||||
if (source === 'local') {
|
||||
localPanel.classList.remove('hidden');
|
||||
onlinePanel.classList.add('hidden');
|
||||
// 切换到本地模型时加载模型列表
|
||||
loadLocalModels();
|
||||
} else {
|
||||
localPanel.classList.add('hidden');
|
||||
onlinePanel.classList.remove('hidden');
|
||||
@@ -484,6 +508,36 @@
|
||||
// 为了兼容性,保留 online 作为别名
|
||||
window.toggleModelSource = toggleModelSource;
|
||||
|
||||
// 加载本地模型列表
|
||||
async function loadLocalModels() {
|
||||
const select = document.getElementById('localModelSelect');
|
||||
if (!select) return;
|
||||
|
||||
// 检查是否已经加载过
|
||||
if (select.options.length > 1) return;
|
||||
|
||||
try {
|
||||
const response = await fetch(`${API_BASE}/local-models`);
|
||||
const result = await response.json();
|
||||
|
||||
if (result.code === 0 && result.data && result.data.models) {
|
||||
result.data.models.forEach(model => {
|
||||
const option = document.createElement('option');
|
||||
option.value = model.path;
|
||||
option.textContent = model.name;
|
||||
select.appendChild(option);
|
||||
});
|
||||
}
|
||||
} catch (error) {
|
||||
console.warn('加载本地模型列表失败:', error);
|
||||
}
|
||||
}
|
||||
|
||||
// 模型选择变化
|
||||
function onModelSelectChange() {
|
||||
// 保留空函数以兼容可能的其他调用
|
||||
}
|
||||
|
||||
// 提交表单
|
||||
async function submitForm() {
|
||||
console.log('submitForm called');
|
||||
|
||||
Reference in New Issue
Block a user