import asyncio import logging import os import sys # 导入教学辅助工具 from TeacherHelper.Kit.TeacherHelper import ( generate_gravitation_lesson_plan, save_lesson_plan ) # 配置日志 logging.basicConfig(level=logging.INFO) logger = logging.getLogger(__name__) # 测试生成教案的函数 async def test_generate_lesson_plan(): print("\n===== 测试生成万有引力教案 =====") try: # 调用教学辅助工具生成教案 lesson_plan_chunks = await generate_gravitation_lesson_plan() output_file = "./markdown/万有引力教案.md" # 调用教学辅助工具保存文件 print("\n生成的教案:") full_content, success = await save_lesson_plan(lesson_plan_chunks, output_file, stream_print=True) if success: print(full_content) print(f"\n教案已保存到:{os.path.abspath(output_file)}") else: print("\n教案保存失败") except Exception as e: print(f"生成教案时发生异常: {str(e)}", file=sys.stderr) # 主函数 async def main(): try: # 直接生成教案,不进行交互式测试 await test_generate_lesson_plan() except KeyboardInterrupt: print("\n程序被用户中断") except Exception as e: print(f"测试过程中发生异常: {str(e)}", file=sys.stderr) finally: print("\n测试程序结束") if __name__ == '__main__': # 运行异步主函数 asyncio.run(main())