Skip to content

Commit 8db7dff

Browse files
nodeeeeeeclaude
andcommitted
Include more visual-element images in generated notes
- Update system prompts (EN+CN) to instruct LLM to insert all slides with visual elements (diagrams, charts, code screenshots, etc.) and only exclude administrative/non-course elements - Raise image hints word-count threshold from 30 to 80 so more slides are offered as available images to the LLM - Raise IMAGE_FILTER_HEURISTIC from 35 to 80 so fewer slides are auto-removed by the heuristic filter - Update vision API prompt: keep code screenshots, only remove purely text or clearly administrative slides - Change spacing guidance from "every 2-3 paragraphs" to "as many as are available" for visual-element images Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 1748e9e commit 8db7dff

1 file changed

Lines changed: 26 additions & 29 deletions

File tree

note_generation.py

Lines changed: 26 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -101,9 +101,9 @@
101101
> 内容
102102
7. 有趣类比或助记技巧用斜体。
103103
8. 图片插入规则(严格遵守):
104-
- **仅插入含视觉元素的图片**:图表、流程图、架构图、代码截图、数学推导、数据可视化等。
105-
- **禁止插入纯文字图片**:纯文字要点、定义、标题幻灯片——笔记本身已用文字表达更好。
106-
- 每隔 2–3 个概念段落插入一张图片,紧跟其说明的概念之后。
104+
- **插入且仅插入含视觉元素的图片**:图表、流程图、架构图、代码截图、数学推导、数据可视化等。如果是与课程无关的行政或其他元素(如课程信息、投票二维码、签到提示等),即使是图片也不要插入
105+
- 纯文字要点、定义、标题幻灯片不需要插入——笔记本身已用文字表达更好。
106+
- 尽可能多地插入含视觉元素的图片,紧跟其说明的概念之后。
107107
- 幻灯片格式:`![Slide N](images/LXX/slide_NNN.png) *(一句话描述)*`
108108
- 屏幕录制帧格式:`![Frame N](images/LXX/frame_NNN.png) *(一句话描述)*`
109109
(LXX 由调用方提供,禁止自行修改)。
@@ -126,7 +126,7 @@
126126
要求:
127127
- 本片段对应笔记的二级标题为 `### {lec_num}.{chunk_idx} {chunk_title}`(**不要输出此行**,由调用方添加)
128128
- 详细度:{detail}/10。{detail_instruction}
129-
- 图片插入:**仅插入含图表/代码/公式等视觉元素的图片**,跳过纯文字截图
129+
- 图片插入:**插入所有含视觉元素的图片**(图表、流程图、架构图、代码截图、数学推导、数据可视化等),跳过纯文字截图和与课程无关的行政元素
130130
路径必须完全照抄上方「可用图片」列表中给出的路径(含 images/L** 子目录),禁止自造路径。
131131
每张图片后加一句斜体括号说明:`![Slide N](path) *(说明)*` 或 `![Frame N](path) *(说明)*`
132132
- 代码示例写完整可编译片段(含必要 include/imports),用正确的语言标签(```c, ```cpp, ```python)。
@@ -147,7 +147,7 @@
147147
要求:
148148
- 本片段对应笔记的二级标题为 `### {lec_num}.{chunk_idx} {chunk_title}`(**不要输出此行**)
149149
- 详细度:{detail}/10。{detail_instruction}
150-
- 图片插入:**仅插入含图表/代码/公式等视觉元素的图片**,跳过纯文字截图
150+
- 图片插入:**插入所有含视觉元素的图片**(图表、流程图、架构图、代码截图、数学推导、数据可视化等),跳过纯文字截图和与课程无关的行政元素
151151
路径必须完全照抄上方「可用图片」列表中给出的路径(含 images/L** 子目录),禁止自造路径。
152152
每张图片后加一句斜体括号说明:`![Slide N](path) *(说明)*` 或 `![Frame N](path) *(说明)*`
153153
- 代码示例写完整可编译片段,用正确的语言标签(```c, ```cpp, ```python)。
@@ -203,9 +203,9 @@
203203
> content
204204
7. Use italics for interesting analogies or memory aids.
205205
8. Image insertion rules (strictly follow):
206-
- **Only include images that contain visual elements**: diagrams, flowcharts, graphs, charts, plots, architecture drawings, code screenshots, mathematical derivations with spatial layout, annotated figures, tables with meaningful structure, or any non-trivial visual illustration.
207-
- **Never include images that are purely text**: bullet-point slides, definition slides, title slides, or any frame/slide whose content can be fully expressed in written text. The notes themselves convey text better than a screenshot of text.
208-
- Insert one image every 2–3 concept paragraphs, immediately after the concept it illustrates.
206+
- **Insert all and only images that contain visual elements**: diagrams, flowcharts, architecture drawings, code screenshots, mathematical derivations, data visualizations, tables with meaningful structure, annotated figures, or any non-trivial visual illustration. Do NOT insert administrative or non-course elements (course info slides, polling QR codes, attendance prompts, etc.) even if they contain images.
207+
- Pure text slides (bullet points, definitions, titles) do not need images — the notes express text better than a screenshot.
208+
- Insert as many visual-element images as are available, immediately after the concept they illustrate.
209209
- Format for slide images: `![Slide N](images/LXX/slide_NNN.png) *(one-sentence description)*`
210210
- Format for screen-capture frames: `![Frame N](images/LXX/frame_NNN.png) *(one-sentence description)*`
211211
(LXX is provided by the caller — do not modify it; the caption must be in parentheses wrapped in asterisks exactly as shown).
@@ -228,7 +228,7 @@
228228
Requirements:
229229
- The section heading for this segment is `### {lec_num}.{chunk_idx} {chunk_title}` (**do not output this line** — it is added by the caller).
230230
- Detail level: {detail}/10. {detail_instruction}
231-
- Images: **only include images that contain diagrams, charts, graphs, code screenshots, architecture drawings, or other visual elements that cannot be expressed as text.** Skip images of pure text, bullet points, or definitions — the notes cover that better in writing. Copy the exact path from the "Available images" list (including the images/L** subdirectory). Do not invent paths. After each image, add a one-sentence italic caption: `![Slide N](path) *(caption)*` or `![Frame N](path) *(caption)*`
231+
- Images: **insert all images that contain visual elements** (diagrams, charts, graphs, code screenshots, architecture drawings, data visualizations, mathematical derivations, etc.). Skip images of pure text, bullet points, or administrative/non-course elements. Copy the exact path from the "Available images" list (including the images/L** subdirectory). Do not invent paths. After each image, add a one-sentence italic caption: `![Slide N](path) *(caption)*` or `![Frame N](path) *(caption)*`
232232
- Code examples must be complete and compilable (with necessary includes/imports), using the correct language tag (```c, ```cpp, ```python).
233233
- Only cover the content in this segment; do not introduce material from other lectures.
234234
""",
@@ -247,7 +247,7 @@
247247
Requirements:
248248
- The section heading is `### {lec_num}.{chunk_idx} {chunk_title}` (**do not output this line**).
249249
- Detail level: {detail}/10. {detail_instruction}
250-
- Images: **only include images that contain diagrams, charts, graphs, code screenshots, or visual elements.** Skip images of pure text or bullet points. Copy the exact path from the "Available images" list (including the images/L** subdirectory). Do not invent paths. After each image, add a one-sentence italic caption: `![Slide N](path) *(caption)*` or `![Frame N](path) *(caption)*`
250+
- Images: **insert all images that contain visual elements** (diagrams, charts, graphs, code screenshots, architecture drawings, data visualizations, etc.). Skip images of pure text or administrative/non-course elements. Copy the exact path from the "Available images" list (including the images/L** subdirectory). Do not invent paths. After each image, add a one-sentence italic caption: `![Slide N](path) *(caption)*` or `![Frame N](path) *(caption)*`
251251
- Code examples must be complete and compilable, using the correct language tag (```c, ```cpp, ```python).
252252
""",
253253
verify="""\
@@ -303,7 +303,7 @@ def _detail_instr(level: int) -> str:
303303

304304
IMAGE_FILTER_MODEL = "gpt-4o-mini"
305305
IMAGE_FILTER_WORD_MAX = 12 # slides with ≤ this many words → remove without API call
306-
IMAGE_FILTER_HEURISTIC = 35 # slides with > this many words AND no code/desc → remove
306+
IMAGE_FILTER_HEURISTIC = 80 # slides with > this many words AND no code/desc → remove
307307

308308
# Title/divider patterns that add no visual value
309309
_TITLE_PATTERN = re.compile(
@@ -369,32 +369,26 @@ def _vision_keep(img_path: Path, slide_text: str = "") -> bool:
369369
You are a study-notes curator deciding whether a lecture slide image should be \
370370
embedded in written notes.{context_block}
371371
372-
## TWO conditions must BOTH be true to KEEP an image:
373-
374-
1. The slide contains a meaningful visual element:
372+
## KEEP the image if the slide contains ANY course-relevant visual element:
375373
- Diagrams: system/architecture diagrams, component boxes connected by arrows
376374
- Flowcharts, state machines, decision trees, sequence/timing diagrams
377375
- Memory layouts, address-space maps, cache/pipeline stage illustrations
378376
- Graphs, plots, bar/line/pie charts, scatter plots showing data or trends
379377
- Tables with a meaningful grid structure (comparing options, relationships)
380378
- Mathematical formulas or derivations where spatial layout matters
379+
- Code screenshots or annotated code with visual highlights
381380
- Annotated screenshots, highlighted output, or callout arrows
381+
- Any non-trivial visual illustration related to the course
382382
383-
2. The visual element is RELEVANT to the lecture subject matter:
384-
- The diagram, chart, or figure directly explains or illustrates a concept \
385-
being taught
386-
- It is NOT an administrative or logistical element such as: polling/quiz \
387-
prompts (PollEv, Mentimeter, Kahoot QR codes), attendance check slides, \
388-
course schedule tables, "any questions?" slides, logos, or sponsor slides
389-
390-
## REMOVE if either condition fails:
391-
- Pure text slides (bullet points, prose, definitions) with no diagram
392-
- Code-only slides (code will be reproduced as text in the notes)
383+
## REMOVE only if the slide is clearly non-visual or non-course-related:
384+
- Pure text slides (bullet points, prose, definitions) with absolutely no \
385+
diagram, chart, figure, or visual element
393386
- Title slides, section dividers, agenda/outline, blank slides
394-
- Slides whose only visual is an unrelated administrative element \
395-
(QR code for a poll, login instructions, course info graphics)
387+
- Administrative elements unrelated to the course: polling/quiz prompts \
388+
(PollEv, Mentimeter, Kahoot QR codes), attendance check slides, \
389+
course info graphics, "any questions?" slides, logos, sponsor slides
396390
397-
## Default: when genuinely uncertain about relevance, KEEP.
391+
## Default: when genuinely uncertain, KEEP.
398392
399393
Reply with exactly one word: KEEP or REMOVE."""
400394

@@ -779,8 +773,11 @@ def _build_chunk_prompt(
779773
else:
780774
cache_key = f"page_{s.index}"
781775
desc = img_cache.get(cache_key, "")
782-
if desc or s.word_count < 30 or s.has_code:
783-
note = desc[:80] if desc else ("has code" if s.has_code else "has diagram")
776+
# Include most slides in the available images list — the LLM
777+
# decides which to insert. Only skip slides that are clearly
778+
# heavy-text with no visual/code content and no cached description.
779+
if desc or s.word_count < 80 or s.has_code:
780+
note = desc[:80] if desc else ("has code" if s.has_code else "")
784781
img_hints_lines.append(f" Slide {s.index+1}: `{rel}` — {note}")
785782
image_hints = "\n".join(img_hints_lines) or " (no images for this segment)"
786783

0 commit comments

Comments
 (0)