Files
param-hub-python/templates/models.html
hubian c8d46f6f99 fix: 修复AI模型页面选择器错误导致无法加载
- document.querySelector('#modelsTable thead') 改为 document.querySelector('table thead')
- #modelsTable 是 tbody 的 id,无法通过它找到 thead
- 修复后页面正常加载模型列表
2026-04-29 16:55:18 +08:00

426 lines
20 KiB
HTML

<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>ParamHub - 参数百科</title>
<link rel="icon" type="image/svg+xml" href="/static/favicon.svg">
<script src="https://cdn.tailwindcss.com"></script>
<link href="https://cdn.jsdelivr.net/npm/remixicon@3.5.0/fonts/remixicon.css" rel="stylesheet">
</head>
<body class="bg-gray-50 min-h-screen">
<!-- 导航栏 -->
<nav class="bg-white shadow-sm sticky top-0 z-50">
<div class="max-w-7xl mx-auto px-4 py-3 flex justify-between items-center">
<a href="/" class="flex items-center gap-2">
<i class="ri-dashboard-3-line text-2xl text-indigo-600"></i>
<span class="text-xl font-bold text-gray-800">ParamHub</span>
</a>
<div class="flex gap-4 text-sm" id="topNav">
<!-- 动态加载 -->
</div>
</div>
</nav>
<main class="max-w-7xl mx-auto px-4 py-8">
<!-- 页面标题 -->
<div class="mb-6">
<h1 class="text-2xl font-bold text-gray-800 flex items-center gap-2">
<i class="ri-robot-line text-indigo-600"></i>
模型数据库
</h1>
<p class="text-gray-500 mt-1">AI大模型参数规格一览</p>
</div>
<!-- 子类别选择器 -->
<div class="bg-white rounded-xl shadow-sm p-4 mb-4">
<div class="flex items-center gap-2 mb-2">
<span class="text-sm text-gray-600"><i class="ri-folder-line mr-1"></i>子类别:</span>
</div>
<div class="flex gap-2" id="subcategoryTabs">
<button onclick="selectSubcategory('')" class="px-4 py-2 bg-indigo-600 text-white rounded-lg text-sm" id="subcat-all">
<i class="ri-apps-line mr-1"></i>全部
</button>
<!-- 动态加载子类别 -->
</div>
</div>
<!-- 搜索和筛选 -->
<div class="bg-white rounded-xl shadow-sm p-4 mb-6">
<div class="flex gap-4 items-center">
<div class="flex-1 relative">
<i class="ri-search-line absolute left-3 top-1/2 -translate-y-1/2 text-gray-400"></i>
<input type="text" id="searchInput" placeholder="搜索模型名称或厂商..."
class="w-full pl-10 pr-4 py-2 border border-gray-200 rounded-lg focus:outline-none focus:border-indigo-400"
oninput="loadModels()">
</div>
<select id="sortBy" class="px-4 py-2 border border-gray-200 rounded-lg" onchange="loadModels()">
<option value="default">默认排序(置顶优先)</option>
<option value="publish_date">按发布日期</option>
<option value="views">按热度</option>
<option value="name">按名称</option>
<option value="parameters">按参数量</option>
<option value="mmlu">按MMLU分数</option>
<option value="context_length">按上下文长度</option>
<option value="created_at">按创建时间</option>
</select>
<select id="sortOrder" class="px-4 py-2 border border-gray-200 rounded-lg" onchange="loadModels()">
<option value="desc">降序</option>
<option value="asc">升序</option>
</select>
<select id="filterType" class="px-4 py-2 border border-gray-200 rounded-lg" onchange="loadModels()">
<option value="all">全部</option>
<option value="open">开源</option>
<option value="closed">商业</option>
</select>
</div>
</div>
<!-- 模型列表 -->
<div class="bg-white rounded-xl shadow-sm overflow-hidden">
<table class="w-full">
<thead class="bg-gray-50 border-b">
<tr>
<th class="px-4 py-3 text-left text-sm font-medium text-gray-600">模型名称</th>
<th class="px-4 py-3 text-left text-sm font-medium text-gray-600">厂商</th>
<th class="px-4 py-3 text-left text-sm font-medium text-gray-600">参数量</th>
<th class="px-4 py-3 text-left text-sm font-medium text-gray-600">上下文</th>
<th class="px-4 py-3 text-left text-sm font-medium text-gray-600">MMLU</th>
<th class="px-4 py-3 text-left text-sm font-medium text-gray-600">类型</th>
<th class="px-4 py-3 text-left text-sm font-medium text-gray-600">价格</th>
<th class="px-4 py-3 text-center text-sm font-medium text-gray-600">操作</th>
</tr>
</thead>
<tbody id="modelsTable">
<tr><td colspan="8" class="text-center text-gray-400 py-8">加载中...</td></tr>
</tbody>
</table>
</div>
</main>
<!-- 详情弹窗 -->
<div id="detailModal" class="fixed inset-0 bg-black/50 z-50 hidden flex items-center justify-center">
<div class="bg-white rounded-xl max-w-2xl w-full mx-4 max-h-[80vh] overflow-auto">
<div class="p-6 border-b flex justify-between items-center">
<h2 class="text-xl font-bold text-gray-800" id="modalTitle">模型详情</h2>
<button onclick="closeModal()" class="text-gray-400 hover:text-gray-600">
<i class="ri-close-line text-2xl"></i>
</button>
</div>
<div id="modalContent" class="p-6"></div>
</div>
</div>
<script>
let allModels = [];
let categories = [];
let currentCategory = null;
let currentSubcategory = '';
// 子类别默认特性配置
const DEFAULT_KEY_FEATURES = {
'chat': ['context_length', 'mmlu', 'input_price', 'output_price'],
'code': ['humaneval', 'context_length', 'input_price'],
'reasoning': ['mmlu', 'context_length', 'parameters'],
'vision': ['context_length', 'mmlu', 'input_price']
};
const FEATURE_LABELS = {
'context_length': '上下文',
'mmlu': 'MMLU',
'humaneval': 'HumanEval',
'input_price': '输入价',
'output_price': '输出价',
'parameters': '参数量',
'reasoning_capability': '推理',
'vision_capability': '视觉',
'multimodal': '多模态'
};
// 加载导航栏
async function loadNav() {
const res = await fetch('/api/categories');
categories = await res.json();
// 获取当前类别的子类别
currentCategory = categories.find(c => c.id === 'ai-models');
renderSubcategoryTabs();
const builtinPages = [
{name: '首页', href: '/'},
{name: '工具', href: '/tools'},
{name: '对比', href: '/compare'},
{name: '知识库', href: '/knowledge'}
];
const categoryPages = {
'ai-models': '/models',
'gpus': '/gpus',
'cpus': '/cpus'
};
let navHtml = '';
builtinPages.forEach(p => {
const isActive = window.location.pathname === p.href;
navHtml += `<a href="${p.href}" class="${isActive ? 'text-indigo-600 font-medium' : 'text-gray-600 hover:text-indigo-600'}">${p.name}</a>`;
});
categories.forEach(cat => {
const href = categoryPages[cat.id] || `/category/${cat.id}`;
const isActive = window.location.pathname === href;
navHtml += `<a href="${href}" class="${isActive ? 'text-indigo-600 font-medium' : 'text-gray-600 hover:text-indigo-600'}">${cat.name}</a>`;
});
document.getElementById('topNav').innerHTML = navHtml;
}
// 渲染子类别选择器
function renderSubcategoryTabs() {
const container = document.getElementById('subcategoryTabs');
if (!currentCategory || !currentCategory.subcategories) {
container.innerHTML = '';
return;
}
let html = `<button onclick="selectSubcategory('')" class="px-4 py-2 ${currentSubcategory === '' ? 'bg-indigo-600 text-white' : 'bg-gray-100 text-gray-600 hover:bg-gray-200'} rounded-lg text-sm" id="subcat-all">
<i class="ri-apps-line mr-1"></i>全部
</button>`;
currentCategory.subcategories.forEach(sub => {
const isActive = currentSubcategory === sub.id;
html += `<button onclick="selectSubcategory('${sub.id}')" class="px-4 py-2 ${isActive ? 'bg-indigo-600 text-white' : 'bg-gray-100 text-gray-600 hover:bg-gray-200'} rounded-lg text-sm" id="subcat-${sub.id}">
<i class="${sub.icon || 'ri-folder-line'} mr-1"></i>${sub.name}
</button>`;
});
container.innerHTML = html;
}
// 选择子类别
function selectSubcategory(subId) {
currentSubcategory = subId;
renderSubcategoryTabs();
loadModels();
}
// 获取当前子类别的关键特性
function getKeyFeatures() {
if (!currentSubcategory || !currentCategory || !currentCategory.subcategories) {
return ['parameters', 'context_length', 'mmlu', 'input_price'];
}
const subcat = currentCategory.subcategories.find(s => s.id === currentSubcategory);
if (subcat && subcat.key_features) {
return subcat.key_features;
}
return ['parameters', 'context_length', 'mmlu', 'input_price'];
}
async function loadModels() {
const keyword = document.getElementById('searchInput').value.trim();
const sortBy = document.getElementById('sortBy').value;
const sortOrder = document.getElementById('sortOrder').value;
const filterType = document.getElementById('filterType').value;
let url = `/api/models?sort=${sortBy}&order=${sortOrder}`;
if (keyword) url += `&q=${encodeURIComponent(keyword)}`;
const res = await fetch(url);
let models = await res.json();
allModels = models;
// 本地过滤类型
if (filterType === 'open') {
models = models.filter(m => m.is_open_source);
} else if (filterType === 'closed') {
models = models.filter(m => !m.is_open_source);
}
// 子类别过滤(通过模型名称/描述中的关键词判断)
if (currentSubcategory && currentCategory && currentCategory.subcategories) {
const subcat = currentCategory.subcategories.find(s => s.id === currentSubcategory);
if (subcat) {
// 简化过滤:根据子类别关键词匹配
// 实际应该有 subcategory_id 字段,这里暂时用名称匹配
// 用户可以在后台编辑时指定子类别
models = models.filter(m => {
const subcatField = m.subcategory || m.subcategory_id;
if (subcatField) return subcatField === currentSubcategory;
return true; // 暂时显示全部,等后台支持子类别字段后再过滤
});
}
}
renderModels(models);
}
function renderModels(models) {
if (models.length === 0) {
document.getElementById('modelsTable').innerHTML = `
<tr><td colspan="8" class="text-center text-gray-400 py-8">暂无数据</td></tr>
`;
return;
}
// 动态获取关键特性
const keyFeatures = getKeyFeatures();
// 动态表头
let headerHtml = `
<tr>
<th class="px-4 py-3 text-left text-sm font-medium text-gray-600">模型名称</th>
<th class="px-4 py-3 text-left text-sm font-medium text-gray-600">厂商</th>
`;
keyFeatures.forEach(f => {
headerHtml += `<th class="px-4 py-3 text-left text-sm font-medium text-gray-600">${FEATURE_LABELS[f] || f}</th>`;
});
headerHtml += `
<th class="px-4 py-3 text-left text-sm font-medium text-gray-600">类型</th>
<th class="px-4 py-3 text-center text-sm font-medium text-gray-600">操作</th>
</tr>
`;
document.querySelector('table thead').innerHTML = headerHtml;
// 动态内容
const html = models.map(m => {
let rowHtml = `
<tr class="border-b hover:bg-gray-50 transition ${m.is_pinned ? 'bg-yellow-50' : ''}">
<td class="px-4 py-3">
<div class="flex items-center gap-2">
${m.is_pinned ? '<i class="ri-pushpin-fill text-yellow-500" title="置顶"></i>' : ''}
<div>
<div class="font-medium text-gray-800">${m.name}</div>
<div class="text-xs text-gray-500">${m.architecture || ''}</div>
</div>
</div>
</td>
<td class="px-4 py-3 text-gray-600">${m.organization}</td>
`;
// 关键特性列
keyFeatures.forEach(f => {
const value = formatFeatureValue(f, m);
rowHtml += `<td class="px-4 py-3">${value}</td>`;
});
rowHtml += `
<td class="px-4 py-3">
${m.is_open_source
? '<span class="px-2 py-1 bg-emerald-100 text-emerald-700 rounded text-sm">开源</span>'
: '<span class="px-2 py-1 bg-gray-100 text-gray-700 rounded text-sm">商业</span>'}
</td>
<td class="px-4 py-3 text-center">
<button onclick="showDetail('${m.id}')" class="text-indigo-600 hover:text-indigo-800 text-sm">
<i class="ri-eye-line mr-1"></i>详情
</button>
</td>
</tr>
`;
return rowHtml;
}).join('');
document.getElementById('modelsTable').innerHTML = html;
}
// 格式化特性值
function formatFeatureValue(feature, model) {
const value = model[feature];
if (value === null || value === undefined) return '<span class="text-gray-400">-</span>';
switch (feature) {
case 'parameters':
return `<span class="px-2 py-1 bg-blue-100 text-blue-700 rounded text-sm">${value}B</span>`;
case 'context_length':
return `<span class="text-gray-600">${formatContext(value)}</span>`;
case 'mmlu':
return `<span class="px-2 py-1 bg-green-100 text-green-700 rounded text-sm">${value}%</span>`;
case 'humaneval':
return `<span class="px-2 py-1 bg-purple-100 text-purple-700 rounded text-sm">${value}%</span>`;
case 'input_price':
return `<span class="text-sm text-gray-600">$${value || 0}</span>`;
case 'output_price':
return `<span class="text-sm text-gray-600">$${value || 0}</span>`;
default:
return `<span class="text-gray-600">${value}</span>`;
}
}
function formatContext(len) {
if (!len) return '-';
if (len >= 1000000) return (len / 1000) + 'K';
if (len >= 1000) return (len / 1000) + 'K';
return len;
}
async function showDetail(id) {
const res = await fetch(`/api/models/${id}`);
const model = await res.json();
document.getElementById('modalTitle').textContent = model.name;
document.getElementById('modalContent').innerHTML = `
<div class="grid grid-cols-2 gap-4">
<div class="p-4 bg-gray-50 rounded-lg">
<div class="text-sm text-gray-500">厂商</div>
<div class="font-medium text-gray-800 mt-1">${model.organization}</div>
</div>
<div class="p-4 bg-gray-50 rounded-lg">
<div class="text-sm text-gray-500">架构</div>
<div class="font-medium text-gray-800 mt-1">${model.architecture || '-'}</div>
</div>
<div class="p-4 bg-gray-50 rounded-lg">
<div class="text-sm text-gray-500">参数量</div>
<div class="font-medium text-gray-800 mt-1">${model.parameters}B</div>
</div>
<div class="p-4 bg-gray-50 rounded-lg">
<div class="text-sm text-gray-500">上下文长度</div>
<div class="font-medium text-gray-800 mt-1">${formatContext(model.context_length)}</div>
</div>
<div class="p-4 bg-gray-50 rounded-lg">
<div class="text-sm text-gray-500">MMLU分数</div>
<div class="font-medium text-gray-800 mt-1">${model.mmlu || '-'}%</div>
</div>
<div class="p-4 bg-gray-50 rounded-lg">
<div class="text-sm text-gray-500">HumanEval</div>
<div class="font-medium text-gray-800 mt-1">${model.humaneval || '-'}%</div>
</div>
<div class="p-4 bg-gray-50 rounded-lg">
<div class="text-sm text-gray-500">许可证</div>
<div class="font-medium text-gray-800 mt-1">${model.license || '-'}</div>
</div>
<div class="p-4 bg-gray-50 rounded-lg">
<div class="text-sm text-gray-500">API价格</div>
<div class="font-medium text-gray-800 mt-1">
${model.input_price ? `输入: $${model.input_price}/1K 输出: $${model.output_price}/1K` : '免费'}
</div>
</div>
</div>
<div class="mt-4 p-4 bg-blue-50 rounded-lg">
<div class="text-sm text-blue-600">简介</div>
<div class="text-gray-800 mt-1">${model.description || '暂无描述'}</div>
</div>
`;
document.getElementById('detailModal').classList.remove('hidden');
}
function closeModal() {
document.getElementById('detailModal').classList.add('hidden');
}
// 点击弹窗外部关闭
document.getElementById('detailModal').addEventListener('click', function(e) {
if (e.target === this) closeModal();
});
// 初始化
loadNav();
loadModels();
</script>
</body>
</html>