12 Commits

Author SHA1 Message Date
8066fc4386 chore: 更新版本号到 v1.7.1 2026-04-28 00:28:59 +08:00
9cd9ccd8e0 feat: 子类别管理界面重构,支持可视化增删改
- 添加子类别编辑弹框(subcategoryModal)
- 子类别列表可视化显示(卡片样式)
- 支持添加、编辑、删除子类别
- 表单输入关键特性字段和标签
- 替换原来的JSON文本编辑方式
2026-04-28 00:28:36 +08:00
a9cbd1b2ba chore: 更新版本号到 v1.7.0 2026-04-28 00:17:27 +08:00
685582b7e6 feat: 支持子类别配置和关键特性显示
- 类别数据结构新增 subcategories 字段
- 每个子类别可定义 key_features 和 feature_labels
- 前端模型页面添加子类别选择器
- 表格根据子类别动态显示关键特性列
- 后台管理支持编辑子类别配置(JSON格式)
- 预设了各类别的子类别配置(对话、代码、推理、视觉等)
2026-04-28 00:16:55 +08:00
961322f8ba chore: 更新版本号到 v1.6.0 2026-04-27 19:58:02 +08:00
b40e890e2b feat: 后台管理添加大模型接口配置功能
- 网站配置页面新增 LLM 配置区域
- 支持配置 API 地址、API Key、文本模型、视觉模型
- LLM 配置从 config.json 动态读取
- 不再使用硬编码的 LLM_CONFIG 常量
2026-04-27 19:57:22 +08:00
9525d56ffc fix: 修复f-string花括号转义问题导致的API错误 2026-04-27 18:44:37 +08:00
5433605fec fix: 增强剪贴板粘贴的错误提示,说明HTTPS/localhost限制 2026-04-27 18:40:36 +08:00
b981e30f46 fix: 修复版本号显示 2026-04-27 18:39:41 +08:00
e2d35b6fa0 feat: 支持多图上传和智能解析产品参数
- 新增 /api/parse-images API 预览解析结果
- 智能添加支持多张图片上传和粘贴
- 支持一次解析出多个产品参数
- 所有类别(模型/GPU/CPU/动态分类)都支持图片解析
- 添加 vision_model 配置支持视觉模型
2026-04-27 18:29:06 +08:00
45190980a9 feat: 发布日期、热度、置顶、图片上传功能
- 新增发布日期(publish_date)、热度(views)、置顶(is_pinned)字段
- 后台管理表格显示新字段和置顶操作按钮
- 前端默认排序:置顶优先 → 发布日期最新
- 新增多种排序选项:发布日期、热度、名称等
- 新增图片上传API(支持多图上传)
- 后台管理表单添加图片上传组件(支持文件选择和粘贴)
- 数据创建时自动初始化新字段
2026-04-20 21:25:57 +08:00
627148a87f feat: 知识库数据添加显示开关功能
- knowledge API添加visible字段支持
- 前台过滤隐藏的知识条目(默认)
- 后台显示全部知识条目(all=1)
- 新增toggle knowledge visible API
- 知识库表格增加显示开关列
2026-04-11 02:32:10 +08:00
6 changed files with 1791 additions and 219 deletions

668
app.py
View File

@@ -1,7 +1,7 @@
"""
ParamHub - 参数百科
AI大模型与硬件参数速查平台
v1.1.0 - 新增智能添加和展示开关功能
v1.7.1 - 子类别管理界面重构,支持可视化增删改
"""
from flask import Flask, render_template, jsonify, request
@@ -11,6 +11,10 @@ import requests
from pathlib import Path
from datetime import datetime
import uuid
import time
import os
import base64
from werkzeug.utils import secure_filename
app = Flask(__name__, static_folder='static', static_url_path='/static')
CORS(app)
@@ -19,6 +23,16 @@ CORS(app)
DATA_DIR = Path(__file__).parent / 'data'
DATA_DIR.mkdir(exist_ok=True)
# 图片上传目录
IMAGES_DIR = Path(__file__).parent / 'static' / 'uploads'
IMAGES_DIR.mkdir(parents=True, exist_ok=True)
# 允许的图片格式
ALLOWED_EXTENSIONS = {'png', 'jpg', 'jpeg', 'gif', 'webp'}
def allowed_file(filename):
return '.' in filename and filename.rsplit('.', 1)[1].lower() in ALLOWED_EXTENSIONS
# 数据文件
MODELS_FILE = DATA_DIR / 'models.json'
GPUS_FILE = DATA_DIR / 'gpus.json'
@@ -32,9 +46,10 @@ LLM_CONFIG = {
'base_url': 'http://192.168.2.17:19007/v1',
'api_key': 'xxxx',
'model': 'auto',
'vision_model': 'gpt-4-vision-preview', # 视觉模型(解析图片)
}
# 默认网站配置
# 默认网站配置包含LLM配置
DEFAULT_CONFIG = {
'site_name': 'ParamHub',
'site_subtitle': '参数百科',
@@ -43,12 +58,31 @@ DEFAULT_CONFIG = {
'copyright_year': '2024',
'contact_email': '',
'github_url': '',
# LLM配置
'llm_base_url': 'http://192.168.2.17:19007/v1',
'llm_api_key': '',
'llm_model': 'auto',
'llm_vision_model': 'gpt-4-vision-preview',
}
def get_llm_config():
"""获取LLM配置从config.json动态读取"""
config = load_config()
return {
'base_url': config.get('llm_base_url', DEFAULT_CONFIG['llm_base_url']),
'api_key': config.get('llm_api_key', DEFAULT_CONFIG['llm_api_key']),
'model': config.get('llm_model', DEFAULT_CONFIG['llm_model']),
'vision_model': config.get('llm_vision_model', DEFAULT_CONFIG['llm_vision_model']),
}
def load_config():
"""加载网站配置"""
if CONFIG_FILE.exists():
return json.loads(CONFIG_FILE.read_text(encoding='utf-8'))
loaded = json.loads(CONFIG_FILE.read_text(encoding='utf-8'))
# 合并默认配置(确保新字段存在)
result = DEFAULT_CONFIG.copy()
result.update(loaded)
return result
return DEFAULT_CONFIG.copy()
def save_config(config):
@@ -67,9 +101,10 @@ def save_data(file_path, data):
# ============ 大模型智能解析 ============
def parse_with_llm(text, category_type):
def parse_with_llm(text, category_type, images=None):
"""
使用大模型解析文本,提取结构化数据
使用大模型解析文本/图片,提取结构化数据
支持多张图片输入,可能解析出多个产品
"""
# 根据类型定义字段模板
@@ -124,14 +159,70 @@ def parse_with_llm(text, category_type):
}
fields = field_templates.get(category_type, field_templates['dynamic'])
fields_json = json.dumps(fields, ensure_ascii=False, indent=2)
prompt = f"""请解析以下文本,提取结构化数据。
文本内容:
{text}
# 构建消息内容
content_parts = []
# 如果有图片,添加图片内容
if images and len(images) > 0:
prompt_text = """请分析图片中的产品参数信息,提取结构化数据。
需要提取的字段:
{json.dumps(fields, ensure_ascii=False, indent=2)}
""" + fields_json + """
重要要求:
1. 图片中可能包含1个或多个产品请识别所有产品
2. 如果是多张图片,请综合分析所有图片内容
3. 数字字段只返回数字,不带单位
4. 如果某字段没有提及返回null
5. 返回格式:如果识别到多个产品,返回数组 [对象列表]; 如果只有一个产品,返回单个对象
6. 只返回JSON数据不要其他内容"""
content_parts.append({
"type": "text",
"text": prompt_text
})
# 添加每张图片支持URL或base64
for img in images:
if isinstance(img, str):
if img.startswith('http'):
# URL图片
content_parts.append({
"type": "image_url",
"image_url": {"url": img}
})
elif img.startswith('data:'):
# base64图片
content_parts.append({
"type": "image_url",
"image_url": {"url": img}
})
else:
# 本地路径读取并转为base64
try:
img_path = IMAGES_DIR / img.replace('/static/uploads/', '')
if img_path.exists():
with open(img_path, 'rb') as f:
img_data = base64.b64encode(f.read()).decode()
ext = img_path.suffix.lower()
mime_type = f'image/{ext if ext != "jpg" else "jpeg"}'
content_parts.append({
"type": "image_url",
"image_url": {"url": f"data:{mime_type};base64,{img_data}"}
})
except Exception as e:
print(f"读取图片失败: {e}")
else:
# 纯文本解析
prompt_text = """请解析以下文本,提取结构化数据。
文本内容:
""" + str(text) + """
需要提取的字段:
""" + fields_json + """
要求:
1. 根据文本内容智能提取各个字段的值
@@ -140,24 +231,35 @@ def parse_with_llm(text, category_type):
4. 返回JSON格式不要包含任何其他内容
请直接返回JSON数据"""
content_parts.append({
"type": "text",
"text": prompt_text
})
try:
# 动态获取LLM配置
llm_config = get_llm_config()
# 使用视觉模型解析(如果有图片)
model = llm_config.get('vision_model', 'gpt-4-vision-preview') if images else llm_config['model']
response = requests.post(
f"{LLM_CONFIG['base_url']}/chat/completions",
f"{llm_config['base_url']}/chat/completions",
headers={
"Content-Type": "application/json",
"Authorization": f"Bearer {LLM_CONFIG['api_key']}"
"Authorization": f"Bearer {llm_config['api_key']}"
},
json={
"model": LLM_CONFIG['model'],
"model": model,
"messages": [
{"role": "system", "content": "你是一个数提取助手负责从文本中提取结构化数据。只返回JSON不要其他内容。"},
{"role": "user", "content": prompt}
{"role": "system", "content": "你是一个产品参数提取助手,负责从文本和图片中提取结构化的产品参数数据。只返回JSON不要其他内容。如果图片中包含多个产品,返回数组。"},
{"role": "user", "content": content_parts}
],
"max_tokens": 1000,
"max_tokens": 2000,
"temperature": 0.1
},
timeout=30
timeout=60
)
if response.status_code == 200:
@@ -172,28 +274,38 @@ def parse_with_llm(text, category_type):
# 解析JSON
parsed = json.loads(content)
# 清理null值
cleaned = {}
for k, v in parsed.items():
if v is not None and v != '' and v != 'null':
# 尝试转换数字
if isinstance(v, str):
try:
if '.' in v:
cleaned[k] = float(v)
else:
cleaned[k] = int(v)
except:
cleaned[k] = v
else:
cleaned[k] = v
# 处理结果(可能是数组或单个对象)
results = []
if isinstance(parsed, list):
results = parsed
else:
results = [parsed]
return cleaned
# 清理每个结果的null值
cleaned_results = []
for item in results:
cleaned = {}
for k, v in item.items():
if v is not None and v != '' and v != 'null':
# 尝试转换数字
if isinstance(v, str):
try:
if '.' in v:
cleaned[k] = float(v)
else:
cleaned[k] = int(v)
except:
cleaned[k] = v
else:
cleaned[k] = v
cleaned_results.append(cleaned)
return cleaned_results
except Exception as e:
print(f"LLM解析失败: {e}")
# 降级处理:返回基本结构
return {'name': text[:50], 'description': text}
return [{'name': text[:50] if text else '未命名产品', 'description': text}]
# ============ 页面路由 ============
@@ -267,21 +379,51 @@ def api_models():
keyword in m.get('organization', '').lower()]
# 排序
sort_by = request.args.get('sort', 'created_at')
reverse = request.args.get('order', 'asc') == 'desc'
sort_by = request.args.get('sort', 'default')
reverse = request.args.get('order', 'desc') == 'desc'
# 安全排序处理可能的None/缺失值
def safe_sort_key(x, key):
val = x.get(key)
if val is None:
return 0 if key in ['parameters', 'context_length', 'mmlu'] else ''
if key in ['parameters', 'context_length', 'mmlu', 'views']:
return 0
elif key in ['publish_date', 'created_at', 'updated_at']:
return ''
return ''
return val
if sort_by in ['name', 'parameters', 'context_length', 'mmlu', 'created_at']:
# 默认排序:置顶优先 → 发布日期最新
if sort_by == 'default':
# 先按置顶排序,再按发布日期排序
def default_sort_key(x):
is_pinned = x.get('is_pinned', False)
publish_date = x.get('publish_date', '')
created_at = x.get('created_at', '')
# 置顶的排在前面 (True > False)
# 发布日期按时间戳排序(越新的排在前面)
return (not is_pinned, -(parse_date_to_timestamp(publish_date) or parse_date_to_timestamp(created_at) or 0))
models = sorted(models, key=default_sort_key)
elif sort_by in ['name', 'parameters', 'context_length', 'mmlu', 'created_at', 'publish_date', 'views', 'updated_at']:
models = sorted(models, key=lambda x: safe_sort_key(x, sort_by), reverse=reverse)
return jsonify(models)
def parse_date_to_timestamp(date_str):
"""将日期字符串转换为时间戳"""
if not date_str:
return None
try:
# 支持多种格式
for fmt in ['%Y-%m-%d', '%Y-%m-%d %H:%M:%S', '%Y/%m/%d']:
try:
return datetime.strptime(date_str, fmt).timestamp()
except:
pass
return None
except:
return None
@app.route('/api/models/<model_id>')
def api_model_detail(model_id):
"""获取单个模型详情"""
@@ -302,6 +444,9 @@ def api_create_model():
data['id'] = uuid.uuid4().hex[:12]
data['created_at'] = datetime.now().strftime('%Y-%m-%d %H:%M:%S')
data['visible'] = data.get('visible', True) # 默认显示
data['publish_date'] = data.get('publish_date', '') # 发布日期
data['views'] = data.get('views', 0) # 热度/阅读数
data['is_pinned'] = data.get('is_pinned', False) # 置顶
models.append(data)
save_data(MODELS_FILE, models)
@@ -346,97 +491,171 @@ def api_toggle_model_visible(model_id):
return jsonify({'success': True, 'visible': model['visible']})
# ============ 图片解析API预览 ============
@app.route('/api/parse-images', methods=['POST'])
def api_parse_images():
"""
解析图片中的产品参数(预览模式,不保存)
支持多张图片,可能返回多个产品
"""
data = request.get_json()
text = data.get('text', '')
images = data.get('images', [])
category_type = data.get('category_type', 'dynamic')
if not text and not images:
return jsonify({'error': '文本或图片不能都为空'}), 400
if not images:
return jsonify({'error': '请上传至少一张图片'}), 400
# 调用大模型解析
parsed_list = parse_with_llm(text, category_type, images)
return jsonify({
'success': True,
'count': len(parsed_list),
'products': parsed_list,
'raw_text': text,
'images': images
})
# ============ 智能添加API ============
@app.route('/api/models/smart-add', methods=['POST'])
def api_smart_add_model():
"""智能添加模型(粘贴文本解析"""
"""智能添加模型(支持文本和多图解析,可能添加多个产品"""
data = request.get_json()
text = data.get('text', '')
images = data.get('images', [])
if not text:
return jsonify({'error': '文本不能为空'}), 400
if not text and not images:
return jsonify({'error': '文本或图片不能为空'}), 400
# 大模型解析
parsed = parse_with_llm(text, 'model')
# 大模型解析(支持多图)
parsed_list = parse_with_llm(text, 'model', images)
# 补充必要字段
parsed['id'] = uuid.uuid4().hex[:12]
parsed['created_at'] = datetime.now().strftime('%Y-%m-%d %H:%M:%S')
parsed['visible'] = True
parsed['raw_text'] = text # 保存原始文本
# 保存
# 处理多个产品
results = []
models = load_data(MODELS_FILE)
models.append(parsed)
for parsed in parsed_list:
# 补充必要字段
parsed['id'] = uuid.uuid4().hex[:12]
parsed['created_at'] = datetime.now().strftime('%Y-%m-%d %H:%M:%S')
parsed['visible'] = True
parsed['raw_text'] = text # 保存原始文本
parsed['images'] = images # 保存图片
parsed['publish_date'] = parsed.get('publish_date', '')
parsed['views'] = 0
parsed['is_pinned'] = False
models.append(parsed)
results.append(parsed)
save_data(MODELS_FILE, models)
return jsonify(parsed)
# 返回添加的产品列表
return jsonify({'success': True, 'count': len(results), 'products': results})
@app.route('/api/gpus/smart-add', methods=['POST'])
def api_smart_add_gpu():
"""智能添加GPU"""
"""智能添加GPU(支持文本和多图解析)"""
data = request.get_json()
text = data.get('text', '')
images = data.get('images', [])
if not text:
return jsonify({'error': '文本不能为空'}), 400
if not text and not images:
return jsonify({'error': '文本或图片不能为空'}), 400
parsed = parse_with_llm(text, 'gpu')
parsed['id'] = uuid.uuid4().hex[:12]
parsed['created_at'] = datetime.now().strftime('%Y-%m-%d %H:%M:%S')
parsed['visible'] = True
parsed['raw_text'] = text
parsed_list = parse_with_llm(text, 'gpu', images)
results = []
gpus = load_data(GPUS_FILE)
gpus.append(parsed)
for parsed in parsed_list:
parsed['id'] = uuid.uuid4().hex[:12]
parsed['created_at'] = datetime.now().strftime('%Y-%m-%d %H:%M:%S')
parsed['visible'] = True
parsed['raw_text'] = text
parsed['images'] = images
parsed['publish_date'] = parsed.get('publish_date', '')
parsed['views'] = 0
parsed['is_pinned'] = False
gpus.append(parsed)
results.append(parsed)
save_data(GPUS_FILE, gpus)
return jsonify(parsed)
return jsonify({'success': True, 'count': len(results), 'products': results})
@app.route('/api/cpus/smart-add', methods=['POST'])
def api_smart_add_cpu():
"""智能添加CPU"""
"""智能添加CPU(支持文本和多图解析)"""
data = request.get_json()
text = data.get('text', '')
images = data.get('images', [])
if not text:
return jsonify({'error': '文本不能为空'}), 400
if not text and not images:
return jsonify({'error': '文本或图片不能为空'}), 400
parsed = parse_with_llm(text, 'cpu')
parsed['id'] = uuid.uuid4().hex[:12]
parsed['created_at'] = datetime.now().strftime('%Y-%m-%d %H:%M:%S')
parsed['visible'] = True
parsed['raw_text'] = text
parsed_list = parse_with_llm(text, 'cpu', images)
results = []
cpus = load_data(CPUS_FILE)
cpus.append(parsed)
for parsed in parsed_list:
parsed['id'] = uuid.uuid4().hex[:12]
parsed['created_at'] = datetime.now().strftime('%Y-%m-%d %H:%M:%S')
parsed['visible'] = True
parsed['raw_text'] = text
parsed['images'] = images
parsed['publish_date'] = parsed.get('publish_date', '')
parsed['views'] = 0
parsed['is_pinned'] = False
cpus.append(parsed)
results.append(parsed)
save_data(CPUS_FILE, cpus)
return jsonify(parsed)
return jsonify({'success': True, 'count': len(results), 'products': results})
@app.route('/api/items/<category_id>/smart-add', methods=['POST'])
def api_smart_add_item(category_id):
"""智能添加动态分类数据"""
"""智能添加动态分类数据(支持文本和多图解析)"""
data = request.get_json()
text = data.get('text', '')
images = data.get('images', [])
if not text:
return jsonify({'error': '文本不能为空'}), 400
if not text and not images:
return jsonify({'error': '文本或图片不能为空'}), 400
parsed = parse_with_llm(text, 'dynamic')
parsed['id'] = uuid.uuid4().hex[:12]
parsed['category_id'] = category_id
parsed['created_at'] = datetime.now().strftime('%Y-%m-%d %H:%M:%S')
parsed['visible'] = True
parsed['raw_text'] = text
parsed_list = parse_with_llm(text, 'dynamic', images)
results = []
items_file = DATA_DIR / f'items_{category_id}.json'
items = load_data(items_file)
items.append(parsed)
for parsed in parsed_list:
parsed['id'] = uuid.uuid4().hex[:12]
parsed['category_id'] = category_id
parsed['created_at'] = datetime.now().strftime('%Y-%m-%d %H:%M:%S')
parsed['visible'] = True
parsed['raw_text'] = text
parsed['images'] = images
parsed['publish_date'] = parsed.get('publish_date', '')
parsed['views'] = 0
parsed['is_pinned'] = False
items.append(parsed)
results.append(parsed)
save_data(items_file, items)
return jsonify(parsed)
return jsonify({'success': True, 'count': len(results), 'products': results})
# ============ GPU API ============
@@ -455,6 +674,30 @@ def api_gpus():
gpus = [g for g in gpus if keyword in g.get('name', '').lower() or
keyword in g.get('manufacturer', '').lower()]
# 排序
sort_by = request.args.get('sort', 'default')
reverse = request.args.get('order', 'desc') == 'desc'
def safe_sort_key(x, key):
val = x.get(key)
if val is None:
if key in ['memory_gb', 'cuda_cores', 'tensor_cores', 'views']:
return 0
elif key in ['publish_date', 'created_at', 'updated_at']:
return ''
return ''
return val
if sort_by == 'default':
def default_sort_key(x):
is_pinned = x.get('is_pinned', False)
publish_date = x.get('publish_date', '')
created_at = x.get('created_at', '')
return (not is_pinned, -(parse_date_to_timestamp(publish_date) or parse_date_to_timestamp(created_at) or 0))
gpus = sorted(gpus, key=default_sort_key)
elif sort_by in ['name', 'memory_gb', 'price_usd', 'created_at', 'publish_date', 'views', 'updated_at', 'release_year']:
gpus = sorted(gpus, key=lambda x: safe_sort_key(x, sort_by), reverse=reverse)
return jsonify(gpus)
@app.route('/api/gpus/<gpu_id>')
@@ -477,6 +720,9 @@ def api_create_gpu():
data['id'] = uuid.uuid4().hex[:12]
data['created_at'] = datetime.now().strftime('%Y-%m-%d %H:%M:%S')
data['visible'] = data.get('visible', True)
data['publish_date'] = data.get('publish_date', '')
data['views'] = data.get('views', 0)
data['is_pinned'] = data.get('is_pinned', False)
gpus.append(data)
save_data(GPUS_FILE, gpus)
@@ -538,6 +784,30 @@ def api_cpus():
cpus = [c for c in cpus if keyword in c.get('name', '').lower() or
keyword in c.get('manufacturer', '').lower()]
# 排序
sort_by = request.args.get('sort', 'default')
reverse = request.args.get('order', 'desc') == 'desc'
def safe_sort_key(x, key):
val = x.get(key)
if val is None:
if key in ['cores', 'threads', 'views']:
return 0
elif key in ['publish_date', 'created_at', 'updated_at']:
return ''
return ''
return val
if sort_by == 'default':
def default_sort_key(x):
is_pinned = x.get('is_pinned', False)
publish_date = x.get('publish_date', '')
created_at = x.get('created_at', '')
return (not is_pinned, -(parse_date_to_timestamp(publish_date) or parse_date_to_timestamp(created_at) or 0))
cpus = sorted(cpus, key=default_sort_key)
elif sort_by in ['name', 'cores', 'threads', 'price_usd', 'created_at', 'publish_date', 'views', 'updated_at']:
cpus = sorted(cpus, key=lambda x: safe_sort_key(x, sort_by), reverse=reverse)
return jsonify(cpus)
@app.route('/api/cpus/<cpu_id>')
@@ -560,6 +830,9 @@ def api_create_cpu():
data['id'] = uuid.uuid4().hex[:12]
data['created_at'] = datetime.now().strftime('%Y-%m-%d %H:%M:%S')
data['visible'] = data.get('visible', True)
data['publish_date'] = data.get('publish_date', '')
data['views'] = data.get('views', 0)
data['is_pinned'] = data.get('is_pinned', False)
cpus.append(data)
save_data(CPUS_FILE, cpus)
@@ -738,6 +1011,11 @@ def api_knowledge():
"""获取知识列表"""
knowledge = load_data(KNOWLEDGE_FILE)
# 过滤隐藏项(前台默认隐藏)
hide_hidden = request.args.get('all', '0') == '0'
if hide_hidden:
knowledge = [k for k in knowledge if k.get('visible', True)]
keyword = request.args.get('q', '').strip().lower()
if keyword:
knowledge = [k for k in knowledge if keyword in k.get('title', '').lower() or keyword in k.get('content', '').lower()]
@@ -767,6 +1045,7 @@ def api_create_knowledge():
data['id'] = uuid.uuid4().hex[:12]
data['created_at'] = datetime.now().strftime('%Y-%m-%d %H:%M:%S')
data['visible'] = data.get('visible', True) # 默认显示
if 'order' not in data:
data['order'] = len(knowledge)
@@ -800,6 +1079,19 @@ def api_delete_knowledge(knowledge_id):
return jsonify({'success': True})
@app.route('/api/knowledge/<knowledge_id>/visible', methods=['POST'])
def api_toggle_knowledge_visible(knowledge_id):
"""切换知识显示状态"""
knowledge = load_data(KNOWLEDGE_FILE)
item = next((k for k in knowledge if k['id'] == knowledge_id), None)
if not item:
return jsonify({'error': 'Knowledge not found'}), 404
item['visible'] = not item.get('visible', True)
save_data(KNOWLEDGE_FILE, knowledge)
return jsonify({'success': True, 'visible': item['visible']})
# ============ 动态分类数据API ============
@app.route('/api/items/<category_id>')
@@ -813,6 +1105,30 @@ def api_items(category_id):
if hide_hidden:
items = [i for i in items if i.get('visible', True)]
# 排序
sort_by = request.args.get('sort', 'default')
reverse = request.args.get('order', 'desc') == 'desc'
def safe_sort_key(x, key):
val = x.get(key)
if val is None:
if key in ['price', 'views', 'year']:
return 0
elif key in ['publish_date', 'created_at', 'updated_at']:
return ''
return ''
return val
if sort_by == 'default':
def default_sort_key(x):
is_pinned = x.get('is_pinned', False)
publish_date = x.get('publish_date', '')
created_at = x.get('created_at', '')
return (not is_pinned, -(parse_date_to_timestamp(publish_date) or parse_date_to_timestamp(created_at) or 0))
items = sorted(items, key=default_sort_key)
elif sort_by in ['name', 'price', 'year', 'created_at', 'publish_date', 'views', 'updated_at']:
items = sorted(items, key=lambda x: safe_sort_key(x, sort_by), reverse=reverse)
return jsonify(items)
@app.route('/api/items/<category_id>/<item_id>')
@@ -838,6 +1154,9 @@ def api_create_item(category_id):
data['category_id'] = category_id
data['created_at'] = datetime.now().strftime('%Y-%m-%d %H:%M:%S')
data['visible'] = data.get('visible', True)
data['publish_date'] = data.get('publish_date', '')
data['views'] = data.get('views', 0)
data['is_pinned'] = data.get('is_pinned', False)
items.append(data)
save_data(items_file, items)
@@ -885,6 +1204,114 @@ def api_toggle_item_visible(category_id, item_id):
return jsonify({'success': True, 'visible': item['visible']})
# ============ 置顶和热度API ============
@app.route('/api/models/<model_id>/pin', methods=['POST'])
def api_toggle_model_pin(model_id):
"""切换模型置顶状态"""
models = load_data(MODELS_FILE)
model = next((m for m in models if m['id'] == model_id), None)
if not model:
return jsonify({'error': 'Model not found'}), 404
model['is_pinned'] = not model.get('is_pinned', False)
save_data(MODELS_FILE, models)
return jsonify({'success': True, 'is_pinned': model['is_pinned']})
@app.route('/api/models/<model_id>/view', methods=['POST'])
def api_model_view(model_id):
"""增加模型阅读数"""
models = load_data(MODELS_FILE)
model = next((m for m in models if m['id'] == model_id), None)
if not model:
return jsonify({'error': 'Model not found'}), 404
model['views'] = model.get('views', 0) + 1
save_data(MODELS_FILE, models)
return jsonify({'success': True, 'views': model['views']})
@app.route('/api/gpus/<gpu_id>/pin', methods=['POST'])
def api_toggle_gpu_pin(gpu_id):
"""切换GPU置顶状态"""
gpus = load_data(GPUS_FILE)
gpu = next((g for g in gpus if g['id'] == gpu_id), None)
if not gpu:
return jsonify({'error': 'GPU not found'}), 404
gpu['is_pinned'] = not gpu.get('is_pinned', False)
save_data(GPUS_FILE, gpus)
return jsonify({'success': True, 'is_pinned': gpu['is_pinned']})
@app.route('/api/gpus/<gpu_id>/view', methods=['POST'])
def api_gpu_view(gpu_id):
"""增加GPU阅读数"""
gpus = load_data(GPUS_FILE)
gpu = next((g for g in gpus if g['id'] == gpu_id), None)
if not gpu:
return jsonify({'error': 'GPU not found'}), 404
gpu['views'] = gpu.get('views', 0) + 1
save_data(GPUS_FILE, gpus)
return jsonify({'success': True, 'views': gpu['views']})
@app.route('/api/cpus/<cpu_id>/pin', methods=['POST'])
def api_toggle_cpu_pin(cpu_id):
"""切换CPU置顶状态"""
cpus = load_data(CPUS_FILE)
cpu = next((c for c in cpus if c['id'] == cpu_id), None)
if not cpu:
return jsonify({'error': 'CPU not found'}), 404
cpu['is_pinned'] = not cpu.get('is_pinned', False)
save_data(CPUS_FILE, cpus)
return jsonify({'success': True, 'is_pinned': cpu['is_pinned']})
@app.route('/api/cpus/<cpu_id>/view', methods=['POST'])
def api_cpu_view(cpu_id):
"""增加CPU阅读数"""
cpus = load_data(CPUS_FILE)
cpu = next((c for c in cpus if c['id'] == cpu_id), None)
if not cpu:
return jsonify({'error': 'CPU not found'}), 404
cpu['views'] = cpu.get('views', 0) + 1
save_data(CPUS_FILE, cpus)
return jsonify({'success': True, 'views': cpu['views']})
@app.route('/api/items/<category_id>/<item_id>/pin', methods=['POST'])
def api_toggle_item_pin(category_id, item_id):
"""切换动态数据置顶状态"""
items_file = DATA_DIR / f'items_{category_id}.json'
items = load_data(items_file)
item = next((i for i in items if i['id'] == item_id), None)
if not item:
return jsonify({'error': 'Item not found'}), 404
item['is_pinned'] = not item.get('is_pinned', False)
save_data(items_file, items)
return jsonify({'success': True, 'is_pinned': item['is_pinned']})
@app.route('/api/items/<category_id>/<item_id>/view', methods=['POST'])
def api_item_view(category_id, item_id):
"""增加动态数据阅读数"""
items_file = DATA_DIR / f'items_{category_id}.json'
items = load_data(items_file)
item = next((i for i in items if i['id'] == item_id), None)
if not item:
return jsonify({'error': 'Item not found'}), 404
item['views'] = item.get('views', 0) + 1
save_data(items_file, items)
return jsonify({'success': True, 'views': item['views']})
# ============ 网站配置API ============
@app.route('/api/config')
@@ -902,9 +1329,80 @@ def api_update_config():
save_config(config)
return jsonify(config)
# ============ 图片上传API ============
@app.route('/api/upload/image', methods=['POST'])
def api_upload_image():
"""上传图片"""
if 'file' not in request.files:
return jsonify({'error': '没有文件'}), 400
file = request.files['file']
if file.filename == '':
return jsonify({'error': '没有选择文件'}), 400
if not allowed_file(file.filename):
return jsonify({'error': '不允许的文件格式'}), 400
# 生成唯一文件名
ext = file.filename.rsplit('.', 1)[1].lower()
filename = f"{uuid.uuid4().hex[:12]}_{int(time.time())}.{ext}"
# 保存文件
filepath = IMAGES_DIR / filename
file.save(filepath)
# 返回图片URL
return jsonify({
'success': True,
'filename': filename,
'url': f'/static/uploads/{filename}'
})
@app.route('/api/upload/image/base64', methods=['POST'])
def api_upload_image_base64():
"""上传Base64图片"""
data = request.get_json()
image_data = data.get('image', '')
if not image_data:
return jsonify({'error': '没有图片数据'}), 400
# 解析Base64数据
try:
# 移除data:image/xxx;base64,前缀
if 'base64,' in image_data:
image_data = image_data.split('base64,')[1]
# 生成文件名
ext = data.get('ext', 'png')
filename = f"{uuid.uuid4().hex[:12]}_{int(time.time())}.{ext}"
# 保存文件
filepath = IMAGES_DIR / filename
with open(filepath, 'wb') as f:
f.write(base64.b64decode(image_data))
return jsonify({
'success': True,
'filename': filename,
'url': f'/static/uploads/{filename}'
})
except Exception as e:
return jsonify({'error': str(e)}), 400
@app.route('/api/upload/image/delete/<filename>', methods=['DELETE'])
def api_delete_image(filename):
"""删除图片"""
filepath = IMAGES_DIR / filename
if filepath.exists():
filepath.unlink()
return jsonify({'success': True})
return jsonify({'error': '文件不存在'}), 404
if __name__ == '__main__':
print("=" * 50)
print("ParamHub - 参数百科 v1.2.0")
print("ParamHub - 参数百科 v1.7.1")
print("=" * 50)
print(f"访问地址: http://localhost:19010")
print(f"后台管理: http://localhost:19010/admin")

View File

@@ -5,7 +5,54 @@
"icon": "ri-robot-line",
"color": "blue",
"description": "大语言模型、图像模型等AI模型参数",
"order": 1
"order": 1,
"subcategories": [
{
"id": "chat",
"name": "对话模型",
"icon": "ri-chat-3-line",
"key_features": ["context_length", "mmlu", "input_price", "output_price"],
"feature_labels": {
"context_length": "上下文",
"mmlu": "MMLU",
"input_price": "输入价",
"output_price": "输出价"
}
},
{
"id": "code",
"name": "代码模型",
"icon": "ri-code-line",
"key_features": ["humaneval", "context_length", "input_price"],
"feature_labels": {
"humaneval": "HumanEval",
"context_length": "上下文",
"input_price": "输入价"
}
},
{
"id": "reasoning",
"name": "推理模型",
"icon": "ri-lightbulb-line",
"key_features": ["reasoning_capability", "mmlu", "context_length"],
"feature_labels": {
"reasoning_capability": "推理能力",
"mmlu": "MMLU",
"context_length": "上下文"
}
},
{
"id": "vision",
"name": "视觉模型",
"icon": "ri-image-line",
"key_features": ["vision_capability", "multimodal", "context_length"],
"feature_labels": {
"vision_capability": "视觉能力",
"multimodal": "多模态",
"context_length": "上下文"
}
}
]
},
{
"id": "gpus",
@@ -13,7 +60,45 @@
"icon": "ri-cpu-line",
"color": "green",
"description": "NVIDIA、AMD等GPU显卡规格参数",
"order": 2
"order": 2,
"subcategories": [
{
"id": "gaming",
"name": "游戏显卡",
"icon": "ri-gamepad-line",
"key_features": ["memory_gb", "cuda_cores", "price_usd", "fp16_tflops"],
"feature_labels": {
"memory_gb": "显存",
"cuda_cores": "CUDA核心",
"price_usd": "价格",
"fp16_tflops": "FP16性能"
}
},
{
"id": "professional",
"name": "专业显卡",
"icon": "ri-building-line",
"key_features": ["memory_gb", "tensor_cores", "memory_bandwidth_gbs", "price_usd"],
"feature_labels": {
"memory_gb": "显存",
"tensor_cores": "Tensor核心",
"memory_bandwidth_gbs": "带宽",
"price_usd": "价格"
}
},
{
"id": "datacenter",
"name": "数据中心",
"icon": "ri-server-line",
"key_features": ["memory_gb", "tensor_cores", "memory_bandwidth_gbs", "fp16_tflops"],
"feature_labels": {
"memory_gb": "显存",
"tensor_cores": "Tensor核心",
"memory_bandwidth_gbs": "带宽",
"fp16_tflops": "FP16性能"
}
}
]
},
{
"id": "cpus",
@@ -21,7 +106,45 @@
"icon": "ri-cpu-line",
"color": "purple",
"description": "Intel、AMD等CPU处理器参数",
"order": 3
"order": 3,
"subcategories": [
{
"id": "desktop",
"name": "桌面CPU",
"icon": "ri-computer-line",
"key_features": ["cores", "threads", "boost_clock_ghz", "price_usd"],
"feature_labels": {
"cores": "核心",
"threads": "线程",
"boost_clock_ghz": "加速频率",
"price_usd": "价格"
}
},
{
"id": "server",
"name": "服务器CPU",
"icon": "ri-server-line",
"key_features": ["cores", "threads", "l3_cache_mb", "tdp_watts"],
"feature_labels": {
"cores": "核心",
"threads": "线程",
"l3_cache_mb": "L3缓存",
"tdp_watts": "功耗"
}
},
{
"id": "mobile",
"name": "移动CPU",
"icon": "ri-smartphone-line",
"key_features": ["cores", "threads", "base_clock_ghz", "tdp_watts"],
"feature_labels": {
"cores": "核心",
"threads": "线程",
"base_clock_ghz": "基础频率",
"tdp_watts": "功耗"
}
}
]
},
{
"id": "phones",
@@ -30,7 +153,33 @@
"color": "orange",
"description": "各品牌手机参数规格",
"order": 4,
"visible": false
"visible": true,
"subcategories": [
{
"id": "flagship",
"name": "旗舰手机",
"icon": "ri-star-line",
"key_features": ["processor", "ram_gb", "storage_gb", "price"],
"feature_labels": {
"processor": "处理器",
"ram_gb": "内存",
"storage_gb": "存储",
"price": "价格"
}
},
{
"id": "midrange",
"name": "中端手机",
"icon": "ri-price-tag-3-line",
"key_features": ["processor", "ram_gb", "battery_mah", "price"],
"feature_labels": {
"processor": "处理器",
"ram_gb": "内存",
"battery_mah": "电池",
"price": "价格"
}
}
]
},
{
"id": "laptops",
@@ -38,7 +187,33 @@
"icon": "ri-macbook-line",
"color": "teal",
"description": "笔记本电脑、台式机参数",
"order": 5
"order": 5,
"subcategories": [
{
"id": "gaming-laptop",
"name": "游戏笔记本",
"icon": "ri-gamepad-line",
"key_features": ["processor", "gpu", "ram_gb", "price"],
"feature_labels": {
"processor": "处理器",
"gpu": "显卡",
"ram_gb": "内存",
"price": "价格"
}
},
{
"id": "business-laptop",
"name": "商务笔记本",
"icon": "ri-briefcase-line",
"key_features": ["processor", "ram_gb", "weight_kg", "price"],
"feature_labels": {
"processor": "处理器",
"ram_gb": "内存",
"weight_kg": "重量",
"price": "价格"
}
}
]
},
{
"id": "021dc76d36be",
@@ -47,6 +222,66 @@
"color": "red",
"order": 6,
"description": "汽车方面",
"created_at": "2026-04-09 10:09:01"
"created_at": "2026-04-09 10:09:01",
"subcategories": [
{
"id": "sedan",
"name": "轿车",
"icon": "ri-car-line",
"key_features": ["engine", "power_kw", "price"],
"feature_labels": {
"engine": "发动机",
"power_kw": "功率",
"price": "价格"
}
},
{
"id": "suv",
"name": "SUV",
"icon": "ri-truck-line",
"key_features": ["engine", "seats", "price"],
"feature_labels": {
"engine": "发动机",
"seats": "座位数",
"price": "价格"
}
}
]
},
{
"id": "71fa2b4d818f",
"name": "摄像",
"icon": "ri-camera-line",
"color": "blue",
"order": 0,
"visible": true,
"description": "相机、摄像机等",
"created_at": "2026-04-25 16:38:47",
"subcategories": [
{
"id": "mirrorless",
"name": "无反相机",
"icon": "ri-camera-line",
"key_features": ["sensor", "megapixels", "video_resolution", "price"],
"feature_labels": {
"sensor": "传感器",
"megapixels": "像素",
"video_resolution": "视频",
"price": "价格"
}
},
{
"id": "dslr",
"name": "单反相机",
"icon": "ri-camera-2-line",
"key_features": ["sensor", "megapixels", "lens_mount", "price"],
"feature_labels": {
"sensor": "传感器",
"megapixels": "像素",
"lens_mount": "卡口",
"price": "价格"
}
}
]
}
]

14
data/config.json Normal file
View File

@@ -0,0 +1,14 @@
{
"site_name": "ParamHub",
"site_subtitle": "参数百科",
"footer_text": "ParamHub - 模型与硬件参数速查平台",
"icp_number": "",
"copyright_year": "2026",
"contact_email": "wlq@tphai.com",
"github_url": "",
"updated_at": "2026-04-27 19:57:00",
"llm_base_url": "http://192.168.2.17:19007/v1",
"llm_api_key": "",
"llm_model": "auto",
"llm_vision_model": "gpt-4-vision-preview"
}

File diff suppressed because it is too large Load Diff

View File

@@ -51,9 +51,16 @@
class="w-full pl-12 pr-4 py-2 border border-gray-200 rounded-lg focus:outline-none focus:border-indigo-400"
onkeyup="filterItems()">
</div>
<select id="sortSelect" onchange="sortItems()" class="px-4 py-2 border border-gray-200 rounded-lg focus:outline-none">
<select id="sortBy" onchange="loadItems()" class="px-4 py-2 border border-gray-200 rounded-lg focus:outline-none">
<option value="default">默认排序(置顶优先)</option>
<option value="publish_date">按发布日期</option>
<option value="views">按热度</option>
<option value="name">按名称</option>
<option value="created_at">按时间</option>
<option value="created_at">创建时间</option>
</select>
<select id="sortOrder" onchange="loadItems()" class="px-4 py-2 border border-gray-200 rounded-lg focus:outline-none">
<option value="desc">降序</option>
<option value="asc">升序</option>
</select>
</div>
</div>
@@ -116,7 +123,9 @@
// 加载数据
async function loadItems() {
const res = await fetch(`/api/items/${categoryId}`);
const sortBy = document.getElementById('sortBy').value;
const sortOrder = document.getElementById('sortOrder').value;
const res = await fetch(`/api/items/${categoryId}?sort=${sortBy}&order=${sortOrder}`);
allItems = await res.json();
document.getElementById('itemCount').textContent = allItems.length;
@@ -137,22 +146,28 @@
document.getElementById('itemsList').innerHTML = items.map(item => {
const fields = Object.entries(item)
.filter(([key, val]) => !['id', 'category_id', 'created_at', 'updated_at'].includes(key) && val)
.filter(([key, val]) => !['id', 'category_id', 'created_at', 'updated_at', 'visible', 'is_pinned', 'views', 'publish_date'].includes(key) && val)
.slice(0, 5)
.map(([key, val]) => `<span class="text-gray-500 text-sm">${key}: ${val}</span>`)
.join('<br>');
return `
<div class="border border-gray-200 rounded-lg p-4 hover:shadow-md transition group">
<div class="border border-gray-200 rounded-lg p-4 hover:shadow-md transition group ${item.is_pinned ? 'bg-yellow-50 border-yellow-300' : ''}">
<div class="flex items-start justify-between">
<div>
<h3 class="font-medium text-gray-800 group-hover:text-indigo-600">${item.name || item.title || '未命名'}</h3>
<h3 class="font-medium text-gray-800 group-hover:text-indigo-600 flex items-center gap-2">
${item.is_pinned ? '<i class="ri-pushpin-fill text-yellow-500" title="置顶"></i>' : ''}
${item.name || item.title || '未命名'}
</h3>
<div class="mt-2 space-y-1">
${fields}
</div>
</div>
<div class="text-xs text-gray-400">
${item.created_at ? item.created_at.split(' ')[0] : ''}
<div class="text-right">
<div class="text-xs text-gray-400">
${item.publish_date || (item.created_at ? item.created_at.split(' ')[0] : '')}
</div>
${item.views ? `<div class="text-xs text-gray-400 mt-1"><i class="ri-eye-line"></i> ${item.views}</div>` : ''}
</div>
</div>
</div>
@@ -176,19 +191,6 @@
renderItems(filtered);
}
// 排序
function sortItems() {
const sortBy = document.getElementById('sortSelect').value;
const sorted = [...allItems].sort((a, b) => {
if (sortBy === 'name') {
return (a.name || a.title || '').localeCompare(b.name || b.title || '');
} else {
return (b.created_at || '').localeCompare(a.created_at || '');
}
});
renderItems(sorted);
}
// 初始化
loadNav();
loadItems();

View File

@@ -32,6 +32,19 @@
<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">
@@ -42,14 +55,18 @@
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="asc">升序</option>
<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>
@@ -97,12 +114,38 @@
<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'},
@@ -130,6 +173,49 @@
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();
@@ -151,6 +237,21 @@
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);
}
@@ -162,38 +263,93 @@
return;
}
const html = models.map(m => `
<tr class="border-b hover:bg-gray-50 transition">
// 动态获取关键特性
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('#modelsTable 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="font-medium text-gray-800">${m.name}</div>
<div class="text-xs text-gray-500">${m.architecture || ''}</div>
<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>
<td class="px-4 py-3">
<span class="px-2 py-1 bg-blue-100 text-blue-700 rounded text-sm">${m.parameters}B</span>
</td>
<td class="px-4 py-3 text-gray-600">${formatContext(m.context_length)}</td>
<td class="px-4 py-3">
<span class="px-2 py-1 bg-green-100 text-green-700 rounded text-sm">${m.mmlu || '-'}%</span>
</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-sm text-gray-600">
${m.input_price ? `$${m.input_price}/$${m.output_price}` : '免费'}
</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>
`).join('');
`;
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 '-';