|
22 | 22 |
|
23 | 23 | OPENAI_RESPONSES_URL = "https://api.openai.com/v1/responses" |
24 | 24 | DEFAULT_MODEL = "gpt-5-mini" |
25 | | -TARGET_SECTIONS = ( |
26 | | - "Problem Summary", |
27 | | - "Data Structures Used", |
28 | | - "Approach", |
29 | | - "Complexity", |
30 | | - "Revision Notes", |
31 | | -) |
32 | | - |
33 | 25 | SYSTEM_INSTRUCTIONS = """ |
34 | 26 | You generate concise LeetCode study notes from a problem statement and an accepted solution. |
35 | 27 | Return only valid JSON with this exact shape: |
@@ -77,15 +69,6 @@ def extract_section_body(content: str, heading: str) -> str: |
77 | 69 | return match.group(1).strip() |
78 | 70 |
|
79 | 71 |
|
80 | | -def section_needs_update(content: str, heading: str) -> bool: |
81 | | - return "TODO" in extract_section_body(content, heading) |
82 | | - |
83 | | - |
84 | | -def complexity_needs_update(content: str) -> bool: |
85 | | - body = extract_section_body(content, "Complexity") |
86 | | - return "TODO" in body |
87 | | - |
88 | | - |
89 | 72 | def format_bullets(values: list[str], fallback: str) -> str: |
90 | 73 | cleaned = [value.strip() for value in values if value and value.strip()] |
91 | 74 | if not cleaned: |
@@ -210,42 +193,31 @@ def build_prompt(slug: str, metadata: dict[str, Any], solution_paths: list[str]) |
210 | 193 | def apply_ai_draft(note_path: Path, draft: dict[str, Any]) -> bool: |
211 | 194 | content = note_path.read_text() |
212 | 195 | updated = content |
213 | | - changed = False |
214 | | - |
215 | | - if section_needs_update(updated, "Problem Summary"): |
216 | | - updated = replace_section(updated, "Problem Summary", str(draft.get("summary") or "TODO")) |
217 | | - changed = True |
218 | | - |
219 | | - if section_needs_update(updated, "Data Structures Used"): |
220 | | - data_structures = draft.get("data_structures") |
221 | | - body = format_bullets(data_structures if isinstance(data_structures, list) else [], "TODO") |
222 | | - updated = replace_section(updated, "Data Structures Used", body) |
223 | | - changed = True |
224 | | - |
225 | | - if section_needs_update(updated, "Approach"): |
226 | | - updated = replace_section(updated, "Approach", str(draft.get("approach") or "TODO")) |
227 | | - changed = True |
228 | | - |
229 | | - if complexity_needs_update(updated): |
230 | | - updated = replace_complexity( |
231 | | - updated, |
232 | | - str(draft.get("time_complexity") or "TODO"), |
233 | | - str(draft.get("space_complexity") or "TODO"), |
234 | | - ) |
235 | | - changed = True |
236 | | - |
237 | | - if section_needs_update(updated, "Revision Notes"): |
238 | | - revision_notes = draft.get("revision_notes") |
239 | | - body = format_bullets( |
240 | | - revision_notes if isinstance(revision_notes, list) else [], |
241 | | - "- TODO", |
242 | | - ) |
243 | | - updated = replace_section(updated, "Revision Notes", body) |
244 | | - changed = True |
245 | | - |
246 | | - if changed: |
| 196 | + data_structures = draft.get("data_structures") |
| 197 | + revision_notes = draft.get("revision_notes") |
| 198 | + |
| 199 | + updated = replace_section(updated, "Problem Summary", str(draft.get("summary") or "TODO")) |
| 200 | + updated = replace_section( |
| 201 | + updated, |
| 202 | + "Data Structures Used", |
| 203 | + format_bullets(data_structures if isinstance(data_structures, list) else [], "TODO"), |
| 204 | + ) |
| 205 | + updated = replace_section(updated, "Approach", str(draft.get("approach") or "TODO")) |
| 206 | + updated = replace_complexity( |
| 207 | + updated, |
| 208 | + str(draft.get("time_complexity") or "TODO"), |
| 209 | + str(draft.get("space_complexity") or "TODO"), |
| 210 | + ) |
| 211 | + updated = replace_section( |
| 212 | + updated, |
| 213 | + "Revision Notes", |
| 214 | + format_bullets(revision_notes if isinstance(revision_notes, list) else [], "- TODO"), |
| 215 | + ) |
| 216 | + |
| 217 | + if updated != content: |
247 | 218 | note_path.write_text(updated) |
248 | | - return changed |
| 219 | + return True |
| 220 | + return False |
249 | 221 |
|
250 | 222 |
|
251 | 223 | def parse_args() -> argparse.Namespace: |
@@ -287,10 +259,6 @@ def main() -> int: |
287 | 259 | if not note_path.exists(): |
288 | 260 | continue |
289 | 261 |
|
290 | | - note_content = note_path.read_text() |
291 | | - if not any(section_needs_update(note_content, heading) for heading in TARGET_SECTIONS if heading != "Complexity") and not complexity_needs_update(note_content): |
292 | | - continue |
293 | | - |
294 | 262 | metadata = get_problem_metadata(slug, cache) |
295 | 263 | prompt = build_prompt(slug, metadata, solution_paths) |
296 | 264 |
|
|
0 commit comments