Skip to content

Commit d3f305f

Browse files
mircealunguclaude
andcommitted
Regenerate daily lesson when user provides a new topic suggestion
Previously, prepare_lesson_generation returned today's cached lesson regardless of topic. Now it deletes the old lesson and regenerates when the user provides a topic that differs from the existing one. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent fcd74a1 commit d3f305f

1 file changed

Lines changed: 13 additions & 4 deletions

File tree

zeeguu/core/audio_lessons/daily_lesson_generator.py

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -63,10 +63,19 @@ def prepare_lesson_generation(self, user, timezone_offset=0, topic_suggestion=No
6363
# Check if a lesson already exists for today
6464
existing_lesson = self.get_todays_lesson_for_user(user, timezone_offset)
6565
if existing_lesson.get("lesson_id"):
66-
log(
67-
f"[prepare_lesson_generation] Found existing lesson {existing_lesson.get('lesson_id')} for today"
68-
)
69-
return existing_lesson
66+
# If the user provided a topic that differs from the existing lesson's,
67+
# delete the old lesson so a new one can be generated with the topic.
68+
existing_topic = existing_lesson.get("topic_suggestion")
69+
if topic_suggestion and topic_suggestion != existing_topic:
70+
log(
71+
f"[prepare_lesson_generation] Topic changed ('{existing_topic}' -> '{topic_suggestion}'), deleting existing lesson"
72+
)
73+
self.delete_todays_lesson_for_user(user, timezone_offset)
74+
else:
75+
log(
76+
f"[prepare_lesson_generation] Found existing lesson {existing_lesson.get('lesson_id')} for today"
77+
)
78+
return existing_lesson
7079
elif existing_lesson.get("error") and existing_lesson.get("status_code") == 404:
7180
# Stale lesson record with missing audio file — delete it so we can regenerate
7281
log(

0 commit comments

Comments
 (0)