From a647179e725ac3df887b999a87b776916099946a Mon Sep 17 00:00:00 2001 From: hubian <908234780@qq.com> Date: Tue, 28 Apr 2026 10:09:58 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=99=BA=E8=83=BD=E8=A1=A5=E5=85=85?= =?UTF-8?q?=E5=8F=82=E6=95=B0=E5=8A=9F=E8=83=BD=20-=20=E7=BC=96=E8=BE=91?= =?UTF-8?q?=E5=B7=B2=E6=9C=89=E4=BA=A7=E5=93=81=E6=97=B6=E4=B8=8A=E4=BC=A0?= =?UTF-8?q?=E5=9B=BE=E7=89=87/=E6=96=87=E6=9C=AC=E8=A1=A5=E5=85=85?= =?UTF-8?q?=E7=BC=BA=E5=A4=B1=E5=AD=97=E6=AE=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app.py | 162 +++++++++++++++++++++++++++ data/categories.json | 154 +++++++++++++++++++------ data/models.json | 4 +- templates/admin.html | 259 +++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 544 insertions(+), 35 deletions(-) diff --git a/app.py b/app.py index aff3a00..6a3b4eb 100644 --- a/app.py +++ b/app.py @@ -523,6 +523,168 @@ def api_parse_images(): # ============ 智能添加API ============ +# ============ 智能补充参数API ============ + +@app.route('/api/models//smart-update', methods=['POST']) +def api_smart_update_model(model_id): + """智能补充模型参数(只填充缺失字段)""" + data = request.get_json() + text = data.get('text', '') + images = data.get('images', []) + + if not text and not images: + return jsonify({'error': '文本或图片不能都为空'}), 400 + + # 获取现有数据 + 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 + + # 解析新参数 + parsed_list = parse_with_llm(text, 'model', images) + if not parsed_list: + return jsonify({'error': '解析失败'}), 500 + + parsed = parsed_list[0] # 补充只取第一个 + + # 只填充缺失或为空的字段 + updated_fields = [] + for key, value in parsed.items(): + if value is not None and value != '' and value != 0: + existing = model.get(key) + if existing is None or existing == '' or existing == 0: + model[key] = value + updated_fields.append(key) + + model['updated_at'] = datetime.now().strftime('%Y-%m-%d %H:%M:%S') + model['raw_text'] = model.get('raw_text', '') + '\n' + text if text else model.get('raw_text', '') + if images: + existing_images = model.get('images', []) + model['images'] = existing_images + images + + save_data(MODELS_FILE, models) + + return jsonify({'success': True, 'updated_fields': updated_fields, 'model': model}) + +@app.route('/api/gpus//smart-update', methods=['POST']) +def api_smart_update_gpu(gpu_id): + """智能补充GPU参数(只填充缺失字段)""" + data = request.get_json() + text = data.get('text', '') + images = data.get('images', []) + + if not text and not images: + return jsonify({'error': '文本或图片不能都为空'}), 400 + + 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 + + parsed_list = parse_with_llm(text, 'gpu', images) + if not parsed_list: + return jsonify({'error': '解析失败'}), 500 + + parsed = parsed_list[0] + + updated_fields = [] + for key, value in parsed.items(): + if value is not None and value != '' and value != 0: + existing = gpu.get(key) + if existing is None or existing == '' or existing == 0: + gpu[key] = value + updated_fields.append(key) + + gpu['updated_at'] = datetime.now().strftime('%Y-%m-%d %H:%M:%S') + gpu['raw_text'] = gpu.get('raw_text', '') + '\n' + text if text else gpu.get('raw_text', '') + if images: + existing_images = gpu.get('images', []) + gpu['images'] = existing_images + images + + save_data(GPUS_FILE, gpus) + + return jsonify({'success': True, 'updated_fields': updated_fields, 'gpu': gpu}) + +@app.route('/api/cpus//smart-update', methods=['POST']) +def api_smart_update_cpu(cpu_id): + """智能补充CPU参数(只填充缺失字段)""" + data = request.get_json() + text = data.get('text', '') + images = data.get('images', []) + + if not text and not images: + return jsonify({'error': '文本或图片不能都为空'}), 400 + + 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 + + parsed_list = parse_with_llm(text, 'cpu', images) + if not parsed_list: + return jsonify({'error': '解析失败'}), 500 + + parsed = parsed_list[0] + + updated_fields = [] + for key, value in parsed.items(): + if value is not None and value != '' and value != 0: + existing = cpu.get(key) + if existing is None or existing == '' or existing == 0: + cpu[key] = value + updated_fields.append(key) + + cpu['updated_at'] = datetime.now().strftime('%Y-%m-%d %H:%M:%S') + cpu['raw_text'] = cpu.get('raw_text', '') + '\n' + text if text else cpu.get('raw_text', '') + if images: + existing_images = cpu.get('images', []) + cpu['images'] = existing_images + images + + save_data(CPUS_FILE, cpus) + + return jsonify({'success': True, 'updated_fields': updated_fields, 'cpu': cpu}) + +@app.route('/api/items///smart-update', methods=['POST']) +def api_smart_update_item(category_id, item_id): + """智能补充动态分类数据参数(只填充缺失字段)""" + data = request.get_json() + text = data.get('text', '') + images = data.get('images', []) + + if not text and not images: + return jsonify({'error': '文本或图片不能都为空'}), 400 + + 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 + + parsed_list = parse_with_llm(text, 'dynamic', images) + if not parsed_list: + return jsonify({'error': '解析失败'}), 500 + + parsed = parsed_list[0] + + updated_fields = [] + for key, value in parsed.items(): + if value is not None and value != '' and value != 0: + existing = item.get(key) + if existing is None or existing == '' or existing == 0: + item[key] = value + updated_fields.append(key) + + item['updated_at'] = datetime.now().strftime('%Y-%m-%d %H:%M:%S') + item['raw_text'] = item.get('raw_text', '') + '\n' + text if text else item.get('raw_text', '') + if images: + existing_images = item.get('images', []) + item['images'] = existing_images + images + + save_data(items_file, items) + + return jsonify({'success': True, 'updated_fields': updated_fields, 'item': item}) + @app.route('/api/models/smart-add', methods=['POST']) def api_smart_add_model(): """智能添加模型(支持文本和多图解析,可能添加多个产品)""" diff --git a/data/categories.json b/data/categories.json index dffd11b..9975f21 100644 --- a/data/categories.json +++ b/data/categories.json @@ -11,7 +11,12 @@ "id": "chat", "name": "对话模型", "icon": "ri-chat-3-line", - "key_features": ["context_length", "mmlu", "input_price", "output_price"], + "key_features": [ + "context_length", + "mmlu", + "input_price", + "output_price" + ], "feature_labels": { "context_length": "上下文", "mmlu": "MMLU", @@ -23,7 +28,11 @@ "id": "code", "name": "代码模型", "icon": "ri-code-line", - "key_features": ["humaneval", "context_length", "input_price"], + "key_features": [ + "humaneval", + "context_length", + "input_price" + ], "feature_labels": { "humaneval": "HumanEval", "context_length": "上下文", @@ -34,7 +43,11 @@ "id": "reasoning", "name": "推理模型", "icon": "ri-lightbulb-line", - "key_features": ["reasoning_capability", "mmlu", "context_length"], + "key_features": [ + "reasoning_capability", + "mmlu", + "context_length" + ], "feature_labels": { "reasoning_capability": "推理能力", "mmlu": "MMLU", @@ -45,7 +58,11 @@ "id": "vision", "name": "视觉模型", "icon": "ri-image-line", - "key_features": ["vision_capability", "multimodal", "context_length"], + "key_features": [ + "vision_capability", + "multimodal", + "context_length" + ], "feature_labels": { "vision_capability": "视觉能力", "multimodal": "多模态", @@ -66,7 +83,12 @@ "id": "gaming", "name": "游戏显卡", "icon": "ri-gamepad-line", - "key_features": ["memory_gb", "cuda_cores", "price_usd", "fp16_tflops"], + "key_features": [ + "memory_gb", + "cuda_cores", + "price_usd", + "fp16_tflops" + ], "feature_labels": { "memory_gb": "显存", "cuda_cores": "CUDA核心", @@ -78,7 +100,12 @@ "id": "professional", "name": "专业显卡", "icon": "ri-building-line", - "key_features": ["memory_gb", "tensor_cores", "memory_bandwidth_gbs", "price_usd"], + "key_features": [ + "memory_gb", + "tensor_cores", + "memory_bandwidth_gbs", + "price_usd" + ], "feature_labels": { "memory_gb": "显存", "tensor_cores": "Tensor核心", @@ -90,7 +117,12 @@ "id": "datacenter", "name": "数据中心", "icon": "ri-server-line", - "key_features": ["memory_gb", "tensor_cores", "memory_bandwidth_gbs", "fp16_tflops"], + "key_features": [ + "memory_gb", + "tensor_cores", + "memory_bandwidth_gbs", + "fp16_tflops" + ], "feature_labels": { "memory_gb": "显存", "tensor_cores": "Tensor核心", @@ -112,7 +144,12 @@ "id": "desktop", "name": "桌面CPU", "icon": "ri-computer-line", - "key_features": ["cores", "threads", "boost_clock_ghz", "price_usd"], + "key_features": [ + "cores", + "threads", + "boost_clock_ghz", + "price_usd" + ], "feature_labels": { "cores": "核心", "threads": "线程", @@ -124,7 +161,12 @@ "id": "server", "name": "服务器CPU", "icon": "ri-server-line", - "key_features": ["cores", "threads", "l3_cache_mb", "tdp_watts"], + "key_features": [ + "cores", + "threads", + "l3_cache_mb", + "tdp_watts" + ], "feature_labels": { "cores": "核心", "threads": "线程", @@ -136,7 +178,12 @@ "id": "mobile", "name": "移动CPU", "icon": "ri-smartphone-line", - "key_features": ["cores", "threads", "base_clock_ghz", "tdp_watts"], + "key_features": [ + "cores", + "threads", + "base_clock_ghz", + "tdp_watts" + ], "feature_labels": { "cores": "核心", "threads": "线程", @@ -159,7 +206,12 @@ "id": "flagship", "name": "旗舰手机", "icon": "ri-star-line", - "key_features": ["processor", "ram_gb", "storage_gb", "price"], + "key_features": [ + "processor", + "ram_gb", + "storage_gb", + "price" + ], "feature_labels": { "processor": "处理器", "ram_gb": "内存", @@ -171,7 +223,12 @@ "id": "midrange", "name": "中端手机", "icon": "ri-price-tag-3-line", - "key_features": ["processor", "ram_gb", "battery_mah", "price"], + "key_features": [ + "processor", + "ram_gb", + "battery_mah", + "price" + ], "feature_labels": { "processor": "处理器", "ram_gb": "内存", @@ -193,7 +250,12 @@ "id": "gaming-laptop", "name": "游戏笔记本", "icon": "ri-gamepad-line", - "key_features": ["processor", "gpu", "ram_gb", "price"], + "key_features": [ + "processor", + "gpu", + "ram_gb", + "price" + ], "feature_labels": { "processor": "处理器", "gpu": "显卡", @@ -205,7 +267,12 @@ "id": "business-laptop", "name": "商务笔记本", "icon": "ri-briefcase-line", - "key_features": ["processor", "ram_gb", "weight_kg", "price"], + "key_features": [ + "processor", + "ram_gb", + "weight_kg", + "price" + ], "feature_labels": { "processor": "处理器", "ram_gb": "内存", @@ -228,7 +295,11 @@ "id": "sedan", "name": "轿车", "icon": "ri-car-line", - "key_features": ["engine", "power_kw", "price"], + "key_features": [ + "engine", + "power_kw", + "price" + ], "feature_labels": { "engine": "发动机", "power_kw": "功率", @@ -239,7 +310,11 @@ "id": "suv", "name": "SUV", "icon": "ri-truck-line", - "key_features": ["engine", "seats", "price"], + "key_features": [ + "engine", + "seats", + "price" + ], "feature_labels": { "engine": "发动机", "seats": "座位数", @@ -253,35 +328,46 @@ "name": "摄像", "icon": "ri-camera-line", "color": "blue", - "order": 0, + "order": 9, "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": "价格" - } + "price": "价格", + "sensor": "传感器", + "video_resolution": "视频" + }, + "icon": "ri-camera-line", + "id": "mirrorless", + "key_features": [ + "sensor", + "megapixels", + "video_resolution", + "price" + ], + "name": "无反相机" }, { - "id": "dslr", - "name": "单反相机", - "icon": "ri-camera-2-line", - "key_features": ["sensor", "megapixels", "lens_mount", "price"], "feature_labels": { - "sensor": "传感器", - "megapixels": "像素", "lens_mount": "卡口", - "price": "价格" - } + "megapixels": "像素", + "price": "价格", + "sensor": "传感器" + }, + "icon": "ri-camera-2-line", + "id": "dslr", + "key_features": [ + "sensor", + "megapixels", + "lens_mount", + "price" + ], + "name": "单反相机" } - ] + ], + "updated_at": "2026-04-28 09:44:52" } ] \ No newline at end of file diff --git a/data/models.json b/data/models.json index 091910b..9e9613a 100644 --- a/data/models.json +++ b/data/models.json @@ -13,7 +13,9 @@ "is_open_source": false, "license": "Proprietary", "description": "OpenAI最强大的多模态大模型", - "created_at": "2024-01-01" + "created_at": "2024-01-01", + "updated_at": "2026-04-28 10:09:47", + "raw_text": "\nGPT-4 Turbo version with 128K context length, price is $10 per 1M input tokens" }, { "id": "gpt4turbo", diff --git a/templates/admin.html b/templates/admin.html index 0df2c70..106faf1 100644 --- a/templates/admin.html +++ b/templates/admin.html @@ -299,6 +299,7 @@
+
@@ -386,6 +387,57 @@ + + +