- 核心改造:不再使用 openclaw 智能体执行处理步骤,改为直接调用大模型接口 - 新增 services/llm_client.py:OpenAI 兼容接口客户端,支持多模型配置管理 - 步骤4/5 由大模型直接完成(提取产品数据、填充字段) - 步骤6 改为直接调用 ParamHub API 提交审核 - 新增 llm_configs 数据库表,默认配置 unsloth/Qwen3.6-27B-Q4_K_M (262144上下文) - 新增 /api/llm 配置管理 API:增删改查、切换激活、测试连接 - 前端首页新增「大模型配置」面板,可随时新增/切换模型 - 处理步骤名称更新为「大模型」版
111 lines
2.8 KiB
Python
111 lines
2.8 KiB
Python
"""
|
|
参数数据自动化管理系统
|
|
"""
|
|
from flask import Flask, jsonify, render_template, send_from_directory
|
|
from flask_cors import CORS
|
|
from config import Config
|
|
from models.database import db
|
|
from utils.scheduler import task_scheduler, setup_auto_process_job
|
|
import logging
|
|
import os
|
|
|
|
# 配置日志
|
|
logging.basicConfig(
|
|
level=logging.INFO,
|
|
format='%(asctime)s - %(name)s - %(levelname)s - %(message)s',
|
|
handlers=[
|
|
logging.FileHandler(os.path.join(Config.LOG_DIR, 'app.log')),
|
|
logging.StreamHandler()
|
|
]
|
|
)
|
|
logger = logging.getLogger('param_auto_manager')
|
|
|
|
# 创建Flask应用
|
|
app = Flask(__name__)
|
|
CORS(app)
|
|
|
|
# 注册路由
|
|
from routes.articles import bp as articles_bp
|
|
from routes.products import bp as products_bp
|
|
from routes.system import bp as system_bp
|
|
from routes.tasks import bp as tasks_bp
|
|
from routes.process_monitor import bp as process_monitor_bp
|
|
from routes.llm import bp as llm_bp
|
|
|
|
app.register_blueprint(articles_bp)
|
|
app.register_blueprint(products_bp)
|
|
app.register_blueprint(system_bp)
|
|
app.register_blueprint(tasks_bp)
|
|
app.register_blueprint(process_monitor_bp)
|
|
app.register_blueprint(llm_bp)
|
|
|
|
# 首页
|
|
@app.route('/')
|
|
def index():
|
|
return render_template('index.html')
|
|
|
|
# 搜索页面
|
|
@app.route('/search')
|
|
def search_page():
|
|
return render_template('search.html')
|
|
|
|
# 内容库页面
|
|
@app.route('/library')
|
|
def library_page():
|
|
return render_template('library.html')
|
|
|
|
# 处理监控页面
|
|
@app.route('/process')
|
|
def process_page():
|
|
return render_template('process.html')
|
|
|
|
# API首页
|
|
@app.route('/api')
|
|
def api_index():
|
|
return jsonify({
|
|
'name': 'Param Auto Manager',
|
|
'version': '1.0.0',
|
|
'description': '参数数据自动化管理系统',
|
|
'endpoints': {
|
|
'articles': '/api/articles',
|
|
'products': '/api/products',
|
|
'system': '/api/system'
|
|
}
|
|
})
|
|
|
|
# 静态文件
|
|
@app.route('/static/<path:filename>')
|
|
def static_files(filename):
|
|
return send_from_directory('static', filename)
|
|
|
|
# 错误处理
|
|
@app.errorhandler(404)
|
|
def not_found(error):
|
|
return jsonify({'error': '资源不存在'}), 404
|
|
|
|
@app.errorhandler(500)
|
|
def internal_error(error):
|
|
return jsonify({'error': '服务器内部错误'}), 500
|
|
|
|
if __name__ == '__main__':
|
|
# 确保日志目录存在
|
|
os.makedirs(Config.LOG_DIR, exist_ok=True)
|
|
os.makedirs(os.path.dirname(Config.DATABASE), exist_ok=True)
|
|
|
|
# 初始化数据库
|
|
logger.info("初始化数据库...")
|
|
|
|
# 设置自动处理任务
|
|
setup_auto_process_job()
|
|
|
|
# 启动定时任务调度器
|
|
task_scheduler.start()
|
|
logger.info("定时任务调度器已启动")
|
|
|
|
# 启动Flask应用
|
|
logger.info(f"启动服务,端口: {Config.PORT}")
|
|
app.run(
|
|
host=Config.HOST,
|
|
port=Config.PORT,
|
|
debug=Config.DEBUG
|
|
) |