"- Only mark genuine downtime as a break — do not use it for slow "
"or informal but still on-topic teaching."
),
)
def analyze_chunk(
agent: Agent, chunk: dict, chunk_index: int, total_chunks: int
) -> list[Lesson]:
"""
Analyze one chunk → list of lessons with timestamps converted to
original video time.
"""
offset = chunk["offset_seconds"]
video_file = upload_chunk(chunk["path"], chunk_index)
print(f" 🤖 Analyzing chunk {chunk_index}/{total_chunks - 1} "
f"(offset={seconds_to_ts(offset)})...")
t0 = time.time()
result = agent.run_sync(
[
(
f"This is chunk {chunk_index} of a longer course video. "
f"The chunk starts at {seconds_to_ts(offset)} in the original video. "
f"Identify all complete 10-15 minute lessons within this chunk. "
f"Timestamps must be relative to THIS CHUNK (00:00:00 = chunk start). "
f"Do NOT include lessons that are cut off at chunk boundaries — "
f"adjacent overlapping chunks will capture them."
),
video_file,
]
)
elapsed = time.time() - t0
chunk_lessons = result.output.lessons
print(f" ✅ {len(chunk_lessons)} lessons found in {elapsed:.0f}s")
# Convert chunk-relative timestamps to original video timestamps
converted = []
for lesson in chunk_lessons:
rel_start = ts_to_seconds(lesson.start_timestamp)
rel_end = ts_to_seconds(lesson.end_timestamp)
abs_start = rel_start + offset
abs_end = rel_end + offset
converted.append(Lesson(
index=0, # will be re-indexed later
start_timestamp=seconds_to_ts(abs_start),
end_timestamp=seconds_to_ts(abs_end),
is_break=lesson.is_break,
# Force the canonical slug for breaks in code, rather than
# trusting the model to use the right literal string.
slug="breaktime" if lesson.is_break else lesson.slug,
title=lesson.title,
summary_markdown_hebrew=lesson.summary_markdown_hebrew,
))
return converted
המשך הקוד לוקח את כל המידע שהסוכן החזיר ובעזרתו שובר את ההקלטה הארוכה לקטעים קצרים ומוסיף את קבצי הסיכום. סך הכל התוכנית לא מאוד ארוכה (פחות מ 500 שורות) וחושפת את היופי בפיתוח סקריפטים היום: יש לנו יכולת חדשה שקודם לא היתה, היכולת להיעזר במודלי שפה כדי לפענח מידע. מתוך 500 שורות הרוב המוחלט הוא קוד פייתון שאפשר היה לכתוב גם לפני שלוש שנים והיה עובד אותו דבר - קריאת API אחת היא זו שמחזיקה את כל הקסם.
