2025-07-08 18:24:23 +08:00
|
|
|
#!/usr/bin/env python3
|
|
|
|
|
# -*- coding: utf-8 -*-
|
2025-04-22 17:36:29 +08:00
|
|
|
|
2025-07-08 18:24:23 +08:00
|
|
|
"""
|
|
|
|
|
主程序入口
|
|
|
|
|
负责初始化和运行内容生成流程
|
|
|
|
|
"""
|
2025-04-22 17:36:29 +08:00
|
|
|
|
2025-07-08 18:24:23 +08:00
|
|
|
import argparse
|
|
|
|
|
import logging
|
|
|
|
|
import time
|
|
|
|
|
from datetime import datetime
|
2025-07-09 11:51:49 +08:00
|
|
|
import asyncio
|
2025-04-22 17:36:29 +08:00
|
|
|
|
2025-07-08 18:24:23 +08:00
|
|
|
from utils.pipeline import PipelineManager
|
|
|
|
|
from core.exception import TravelContentCreatorError
|
2025-04-22 14:16:29 +08:00
|
|
|
|
2025-07-08 18:24:23 +08:00
|
|
|
def setup_logging():
|
|
|
|
|
"""配置日志记录"""
|
2025-04-22 17:36:29 +08:00
|
|
|
logging.basicConfig(
|
2025-07-08 18:24:23 +08:00
|
|
|
level=logging.INFO,
|
|
|
|
|
format='%(asctime)s - %(name)s - %(levelname)s - %(message)s',
|
2025-04-22 17:36:29 +08:00
|
|
|
datefmt='%Y-%m-%d %H:%M:%S'
|
|
|
|
|
)
|
2025-07-08 18:24:23 +08:00
|
|
|
# 可以为特定模块设置不同的日志级别
|
|
|
|
|
logging.getLogger("core.ai.AIAgent").setLevel(logging.DEBUG)
|
2025-04-22 17:36:29 +08:00
|
|
|
|
2025-07-09 11:51:49 +08:00
|
|
|
async def main():
|
2025-07-08 18:24:23 +08:00
|
|
|
"""主函数"""
|
|
|
|
|
parser = argparse.ArgumentParser(
|
|
|
|
|
description="运行内容生成流程",
|
|
|
|
|
formatter_class=argparse.ArgumentDefaultsHelpFormatter
|
2025-04-22 17:36:29 +08:00
|
|
|
)
|
|
|
|
|
parser.add_argument(
|
2025-07-08 18:24:23 +08:00
|
|
|
"--config_dir",
|
|
|
|
|
type=str,
|
|
|
|
|
default="config",
|
|
|
|
|
help="包含配置文件的目录路径"
|
2025-04-22 17:36:29 +08:00
|
|
|
)
|
|
|
|
|
parser.add_argument(
|
2025-07-08 18:24:23 +08:00
|
|
|
"--run_id",
|
|
|
|
|
type=str,
|
|
|
|
|
default=f"run_{datetime.now().strftime('%Y%m%d_%H%M%S')}",
|
|
|
|
|
help="为本次运行指定一个唯一的ID"
|
2025-04-22 17:36:29 +08:00
|
|
|
)
|
2025-07-08 18:24:23 +08:00
|
|
|
|
2025-04-22 17:36:29 +08:00
|
|
|
args = parser.parse_args()
|
|
|
|
|
|
2025-07-08 18:24:23 +08:00
|
|
|
start_time = time.time()
|
|
|
|
|
setup_logging()
|
|
|
|
|
logging.info(f"--- 开始运行 --- Run ID: {args.run_id} ---")
|
|
|
|
|
logging.info(f"使用配置目录: {args.config_dir}")
|
2025-04-22 17:36:29 +08:00
|
|
|
|
2025-07-08 18:24:23 +08:00
|
|
|
try:
|
|
|
|
|
pipeline = PipelineManager(config_dir=args.config_dir, run_id=args.run_id)
|
2025-07-09 11:51:49 +08:00
|
|
|
await pipeline.run_pipeline()
|
2025-07-08 18:24:23 +08:00
|
|
|
except TravelContentCreatorError as e:
|
|
|
|
|
logging.critical(f"流程发生严重错误: {e}", exc_info=True)
|
|
|
|
|
except Exception as e:
|
|
|
|
|
logging.critical(f"发生未知异常: {e}", exc_info=True)
|
|
|
|
|
finally:
|
|
|
|
|
end_time = time.time()
|
|
|
|
|
logging.info(f"--- 运行结束 --- 耗时: {end_time - start_time:.2f} 秒 ---")
|
2025-04-22 17:36:29 +08:00
|
|
|
|
2025-04-17 15:30:24 +08:00
|
|
|
|
2025-07-08 18:24:23 +08:00
|
|
|
if __name__ == '__main__':
|
2025-07-09 11:51:49 +08:00
|
|
|
asyncio.run(main())
|