83 lines
3.0 KiB
Python
83 lines
3.0 KiB
Python
|
import asyncio
|
|||
|
import logging
|
|||
|
import os
|
|||
|
import sys
|
|||
|
|
|||
|
# 导入教学辅助工具
|
|||
|
from TeacherHelper.Kit.TeacherHelper import (
|
|||
|
LLMClient,
|
|||
|
save_lesson_plan
|
|||
|
)
|
|||
|
|
|||
|
# 配置日志
|
|||
|
logging.basicConfig(level=logging.INFO)
|
|||
|
logger = logging.getLogger(__name__)
|
|||
|
|
|||
|
|
|||
|
async def generate_gravitation_courseware():
|
|||
|
"""生成万有引力课件大纲的异步函数"""
|
|||
|
system_prompt = """你是PPT视觉设计教练,遵循“6×6原则”(每页≤6行,每行≤6词),字体≥28pt,主色调#005BAC(教育蓝),强调色#FFB703(暖黄)。所有动画≤0.5s,禁止花哨。需要给出演示者备注栏(<备注>)。"""
|
|||
|
|
|||
|
llm_client = LLMClient(system_prompt=system_prompt)
|
|||
|
|
|||
|
prompt = """为“万有引力”生成可直接导入PowerPoint的Markdown大纲,共12页,含:
|
|||
|
1. 封面(课程名+章节+教师姓名留白)
|
|||
|
2. 情境导入(1个30s短视频建议+2张图片提示)
|
|||
|
3. 概念建构(苹果落地+月亮绕地对比图)
|
|||
|
4. 规律探究(卡文迪许实验GIF占位)
|
|||
|
5. 公式推导(F=G·m₁m₂/r²分三步行)
|
|||
|
6. 例题精讲(2道,step-by-step动画)
|
|||
|
7. 当堂检测(Padlet二维码占位)
|
|||
|
8. 小结(思维导图,可一键转SmartArt)
|
|||
|
9. 作业二维码(链接到在线表单)
|
|||
|
10. 结束页(“思考:如果没有万有引力?”留白)
|
|||
|
|
|||
|
【格式要求】
|
|||
|
每页用三级标题###表示,下方用<ul>列要点;如需图片,用! `https://via.placeholder.com/800x450?text=Image` 占位并给出版权提示;在要点后另起一行写<备注>演示者话术。"""
|
|||
|
|
|||
|
async def get_courseware():
|
|||
|
async for chunk in llm_client.get_response(prompt, stream=True):
|
|||
|
yield chunk
|
|||
|
|
|||
|
return get_courseware()
|
|||
|
|
|||
|
|
|||
|
# 测试生成课件的函数
|
|||
|
async def test_generate_courseware():
|
|||
|
print("\n===== 测试生成万有引力课件 =====")
|
|||
|
|
|||
|
try:
|
|||
|
# 调用教学辅助工具生成课件
|
|||
|
courseware_chunks = await generate_gravitation_courseware()
|
|||
|
output_file = "./markdown/万有引力课件.md"
|
|||
|
|
|||
|
# 调用教学辅助工具保存文件
|
|||
|
print("\n生成的课件大纲:")
|
|||
|
full_content, success = await save_lesson_plan(courseware_chunks, output_file, stream_print=True)
|
|||
|
|
|||
|
if success:
|
|||
|
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_courseware()
|
|||
|
|
|||
|
except KeyboardInterrupt:
|
|||
|
print("\n程序被用户中断")
|
|||
|
except Exception as e:
|
|||
|
print(f"测试过程中发生异常: {str(e)}", file=sys.stderr)
|
|||
|
finally:
|
|||
|
print("\n测试程序结束")
|
|||
|
|
|||
|
|
|||
|
if __name__ == '__main__':
|
|||
|
# 运行异步主函数
|
|||
|
asyncio.run(main())
|