Newshot

Show HN:Pencil – LLM 以 JSON 形式编写白板课程,由浏览器绘制

Translation(model translation, not the source's own text)

Pencil:旁白白板课程原型

对一个“在白板上作画的 AI 老师”想法的开源小尝试:模型以严格 JSON 写出课程,代码负责校验,浏览器播放器按旁白节奏同步绘制。这里的一切(提示词、schema、播放器)都是原创代码。

在线演示:一节由 DeepSeek 撰写的课程,由单文件播放器播放(按 Play,取消勾选“Silent”以开启语音)。

一节讲解潮汐如何形成的课程正在被逐步绘制(3 倍速播放)
一节讲解潮汐如何形成的课程正在被逐步绘制(3 倍速播放)

        topic --> planner.py --(LLM)--> lesson.json --> validator.js --(issues)--> repair loop
                                                      |
                                                      v
                                       player.html (SVG draw-on + speech, cues by word index)
      

快速开始


        open player.html                       # plays the built-in rainbow sample (no server needed)
node validator.js samples/rainbow.json # exit 0 = valid; prints issues as JSON otherwise

export DEEPSEEK_API_KEY=...           # default provider; stdlib only, no pip install needed
python3 planner.py --topic "How tides work" --minutes 4 --out lesson.json \
    --price-in <USD per 1M input tokens> --price-out <USD per 1M output tokens> --inr-per-usd 88
# then open player.html, "Load a lesson", pick lesson.json
# or: python3 -m http.server and open player.html?src=lesson.json&autoplay=1

# Anthropic instead: pip install anthropic; export ANTHROPIC_API_KEY=...; add --provider anthropic
      

--model(或环境变量 LESSON_MODEL)用于选择模型,默认为 deepseek-flash。价格是有意作为输入参数传入的:planner 会打印每节课的 token 数与成本,方便你测算自己的真实数字。--topic - 表示从 stdin 读取主题;--research-file 用于附加参考资料笔记;--dry-run 会打印提示词。

课程格式

beats[] 中每一项包含旁白以及 ops[]:heading、paragraph、callout、definition、table、figure。figure 由 parts[] 组成,每个 part 包含 marks[](circle、ellipse、rect、line、path、label)。每个 part 都有一个 cue:即旁白中绘制该 part 的词的索引。path 仅使用绝对命令。checks[] 是课程末尾的多选题。

测试


        python3 -m unittest test_planner   # repair loop, parsing, cost math (fake LLM, no key needed)
python3 test_player.py             # headless Chrome: playback, quiz, bad input, XSS safety
python3 build.py                   # regenerate player.html from player.template.html
      

已知限制

  • 单元测试使用脚本化的假模型;实际运行已用 DeepSeek(deepseek-flash)完成。Anthropic 路径尚未进行实际运行测试。
  • 旁白使用浏览器内置的语音合成。若需统一音色,可替换为设备端 TTS。
  • 抖动效果为可选开启:SVG 位移滤镜可能会在细笔画上留下小缺口。
  • 没有账户、存储、上传、视频导出或计费功能。

The translation is machine-generated and individual terms may be off. Nothing is rewritten or cut; the original is authoritative.

Published by HN AI
This site only summarises and aggregates; copyright stays with the original author. Headlines and summaries follow the source — where they differ, the original wins.
Read the original ↗