ToCode: post #6040 — TG.ME

📌 יום 11 - סידור סרטים בקורס

מה תעשו אם העברתם קורס AI והקלטתם את כל ההרצאות שעברו בטימס ועכשיו יש לכם שעות של וידאו בלי אינדקס? תבנו סוכן AI כמובן. בדוגמה היום נבנה סוכן AI שלוקח הקלטה ארוכה ושובר אותה לחלקים קטנים בצירוף אינדקס טקסטואלי מלא לכל חלק כדי שאפשר יהיה לחזור רק לחלקים שאנחנו צריכים.

מה אנחנו בונים

נתונה הקלטה של 4 שעות ממפגש בקורס ואנחנו רוצים לפצל אותה לשיעורים קצרים, כל שיעור בן 5-10 דקות ולכל שיעור לצרף סיכום טקסט כתוב. משימה שביום רגיל היתה לוקחת כמה שעות לבן אדם ו AI יכול לעשות אותה בקלות בצורה עצמאית לגמרי. זה תהליך העבודה:

1. חותכים את ההקלטה לקטעים של 30 דקות כדי שיהיה ל AI קל להתמודד איתם.
2. אנחנו לא יודעים עדיין איפה הכי הגיוני לסמן "שיעור" לכן נדאג לחפיפה של 5 דקות בין הקטעים הקצרים וכך שיעור לא ייפול בדיוק באמצע ביניהם.
3. נעלה כל קטע ל Gemini דרך Google File API.
4. נבקש מהסוכן שיעבור על כל קטע וייתן לי את ה Timestamps בהם הכי הגיוני לחתוך את הקטע לשיעורים.
5. נמזג ונחתוך את ההקלטה לפי הזמנים שקיבלנו מהסוכן ונצרף את הסיכומים.

קוד הדוגמה המלא זמין שוב בתיקיית הדוגמאות והפעם הסוכן כולו שמור בקובץ אחד:

https://github.com/ynonp/pydanticai-demos/blob/main/11-course-builder/build-course.py

נעבור יחד על החלקים המעניינים.

מבנה הפלט

הסוכן יחזיר רשימה של שיעורים וכל שיעור מכיל המון מידע: זמן ההתחלה שלו, זמן הסיום, אינדקס שלו, האם זה שיעור או הפסקה, מזהה שלו וגם סיכום השיעור. כל פריט מידע כזה מגיע במבנה מסוים ועם הוראות מסוימות ונוח לי לרשום את ההוראות שקשורות לכל שדה בתוך הקלאס שמגדיר את מבנה הפלט. פידנטיק מאפשר את זה באמצעות פקודת Field. זה נראה כך:

class Lesson(BaseModel):
index: int = Field(description="1-based lesson number within this chunk")


קלאס השיעור המלא כולל כל ההסברים הוא הקלאס הראשון בקובץ:

class Lesson(BaseModel):
"""A single lesson extracted from the course video."""

index: int = Field(description="1-based lesson number within this chunk")
start_timestamp: str = Field(
description="Start time relative to THIS CHUNK as HH:MM:SS, e.g. '00:02:30'"
)
end_timestamp: str = Field(
description="End time relative to THIS CHUNK as HH:MM:SS, e.g. '00:14:45'"
)
is_break: bool = Field(
default=False,
description=(
"True if this segment is a BREAK with no teaching content — e.g. "
"students chatting, silence, instructor away, coffee/lunch break. "
"False for a normal lesson."
),
)
slug: str = Field(
description=(
"URL-safe slug for the lesson, e.g. 'intro-to-pydantic'. "
"If is_break is True, this is ignored (the slug 'breaktime' is "
"applied automatically) — still provide a placeholder value."
)
)
title: str = Field(description="Lesson title in the original language")
summary_markdown_hebrew: str = Field(
description=(
"A full, self-contained lesson write-up in Hebrew markdown, written so "
"that someone who never watched the video can read it and actually "
"learn the material — NOT a table of contents or a bullet-point index "
"of what was covered. Write it like an article/tutorial: "
"Structure it as numbered sections ('### 1. <topic title>', "
"'### 2. <topic title>', ...), one per sub-topic covered in the "
"lesson, in the order they were taught. Under each heading, write "
"full explanatory paragraphs in flowing Hebrew prose that actually "
"teach the concept (what it is, why it matters, how it works) the "
"way the instructor explained it — not short summaries or fragments. "
"Include exact code shown in the video in fenced code blocks, "
"including commands, filenames, and terminal output where relevant, "
"each with a sentence or two explaining what the code does and why. "
"Include any links or external references mentioned, and end with "
"practical conclusions/recommendations if the instructor gave any. "
GitHub
pydanticai-demos/11-course-builder/build-course.py at main · ynonp/pydanticai-demos
Contribute to ynonp/pydanticai-demos development by creating an account on GitHub.
August 23, 2026 50 1