Flowise-Übungen stabilisieren und Lernfortschritt korrigieren

Vermeide kürzlich angezeigte Sätze bei neuen Übungen und frage Flowise bei Wiederholungen einmal erneut. Validiere strukturierte Antworten, protokolliere die Übungsquelle und schütze nutzerspezifische Übungs-IDs.

Berechne schwierige Wörter anhand der neuesten Aussprache pro Wort. Passe das Lehrerfeedback an gute Bewertungen an und verbessere das Laden neuer Übungen im Web. Ergänze gezielte Go-Tests.
This commit is contained in:
Eugenius Naumenko
2026-10-07 20:52:02 +00:00
parent 74a4caa1c6
commit bac840e091
11 changed files with 572 additions and 119 deletions
+52 -16
View File
@@ -21,9 +21,9 @@ type DataStore interface {
UpdatePreferences(ctx context.Context, userID, uiLanguage, targetLanguage, cefrLevel string, dailyGoalMinutes int) (domain.LearnerProfile, error)
ListLanguages(ctx context.Context) ([]domain.LanguageProfile, error)
GetLanguage(ctx context.Context, code string) (domain.LanguageProfile, error)
NextLessonAndExercise(ctx context.Context, profile domain.LearnerProfile) (domain.Lesson, domain.Exercise, error)
NextLessonAndExercise(ctx context.Context, profile domain.LearnerProfile, avoidReferenceText ...string) (domain.Lesson, domain.Exercise, error)
SaveGeneratedExercise(ctx context.Context, userID string, generated domain.GeneratedExercise) (domain.Lesson, domain.Exercise, error)
GetExercise(ctx context.Context, id string) (domain.Exercise, error)
GetExercise(ctx context.Context, id, userID string) (domain.Exercise, error)
SaveAttempt(ctx context.Context, attempt domain.Attempt) (domain.Attempt, error)
Progress(ctx context.Context, userID string, limit int) (domain.ProgressSummary, error)
CreateConversationSession(ctx context.Context, userID, targetLanguage, cefrLevel string) (domain.ConversationSession, error)
@@ -190,7 +190,7 @@ func (s *Server) dashboard(w http.ResponseWriter, r *http.Request) {
writeError(w, http.StatusInternalServerError, err)
return
}
lesson, exercise, err := s.nextAgentExercise(r.Context(), user, profile, progress)
lesson, exercise, err := s.nextAgentExercise(r.Context(), user, profile, progress, nil)
if err != nil {
writeError(w, http.StatusNotFound, err)
return
@@ -211,6 +211,31 @@ func (s *Server) progress(w http.ResponseWriter, r *http.Request) {
func (s *Server) nextLesson(w http.ResponseWriter, r *http.Request) {
userID := currentUserID(r)
var req struct {
PreviousExerciseID string `json:"previous_exercise_id"`
RecentExerciseIDs []string `json:"recent_exercise_ids"`
}
if err := decodeJSON(r, &req); err != nil && !errors.Is(err, io.EOF) {
writeError(w, http.StatusBadRequest, err)
return
}
recentIDs := req.RecentExerciseIDs
if req.PreviousExerciseID != "" && (len(recentIDs) == 0 || recentIDs[len(recentIDs)-1] != req.PreviousExerciseID) {
recentIDs = append(recentIDs, req.PreviousExerciseID)
}
if len(recentIDs) > 3 {
writeError(w, http.StatusBadRequest, errors.New("at most three recent exercises are allowed"))
return
}
avoidReferenceTexts := make([]string, 0, len(recentIDs))
for _, id := range recentIDs {
previous, err := s.store.GetExercise(r.Context(), id, userID)
if err != nil {
writeError(w, http.StatusNotFound, err)
return
}
avoidReferenceTexts = append(avoidReferenceTexts, previous.TargetText)
}
user, err := s.store.GetUser(r.Context(), userID)
if err != nil {
writeError(w, http.StatusNotFound, err)
@@ -226,7 +251,7 @@ func (s *Server) nextLesson(w http.ResponseWriter, r *http.Request) {
writeError(w, http.StatusInternalServerError, err)
return
}
lesson, exercise, err := s.nextAgentExercise(r.Context(), user, profile, progress)
lesson, exercise, err := s.nextAgentExercise(r.Context(), user, profile, progress, avoidReferenceTexts)
if err != nil {
writeError(w, http.StatusNotFound, err)
return
@@ -234,21 +259,28 @@ func (s *Server) nextLesson(w http.ResponseWriter, r *http.Request) {
writeJSON(w, http.StatusOK, map[string]any{"lesson": lesson, "exercise": exercise})
}
func (s *Server) nextAgentExercise(ctx context.Context, user domain.User, profile domain.LearnerProfile, progress domain.ProgressSummary) (domain.Lesson, domain.Exercise, error) {
func (s *Server) nextAgentExercise(ctx context.Context, user domain.User, profile domain.LearnerProfile, progress domain.ProgressSummary, avoidReferenceTexts []string) (domain.Lesson, domain.Exercise, error) {
avoidReferenceText := ""
if len(avoidReferenceTexts) > 0 {
avoidReferenceText = avoidReferenceTexts[len(avoidReferenceTexts)-1]
}
generated, err := s.teacher.NextExercise(ctx, domain.GeneratedExerciseRequest{
UserID: user.ID,
Profile: profile,
Progress: progress,
TargetLanguage: profile.TargetLanguage,
CEFRLevel: profile.CEFRLevel,
UILanguage: user.UILanguage,
SessionID: flowiseSessionID(user.ID, profile.TargetLanguage, "practice"),
RecentWeakWords: progress.WeakWords,
PreferredType: "repeat_sentence",
UserID: user.ID,
Profile: profile,
Progress: progress,
TargetLanguage: profile.TargetLanguage,
CEFRLevel: profile.CEFRLevel,
UILanguage: user.UILanguage,
SessionID: flowiseSessionID(user.ID, profile.TargetLanguage, "practice"),
RecentWeakWords: progress.WeakWords,
PreferredType: "repeat_sentence",
AvoidReferenceText: avoidReferenceText,
AvoidReferenceTexts: avoidReferenceTexts,
})
if err == nil && generated.Source == "flowise" && strings.TrimSpace(generated.ReferenceText) != "" {
lesson, exercise, saveErr := s.store.SaveGeneratedExercise(ctx, user.ID, generated)
if saveErr == nil {
s.logger.Info("next exercise selected", "request_id", ctx.Value(requestIDKey), "source", exercise.Source, "exercise_id", exercise.ID)
return lesson, exercise, nil
}
s.logger.Warn("saving generated exercise failed, using seed fallback", "error", saveErr)
@@ -256,7 +288,11 @@ func (s *Server) nextAgentExercise(ctx context.Context, user domain.User, profil
if err != nil {
s.logger.Warn("flowise next exercise failed, using seed fallback", "error", err)
}
return s.store.NextLessonAndExercise(ctx, profile)
lesson, exercise, err := s.store.NextLessonAndExercise(ctx, profile, avoidReferenceTexts...)
if err == nil {
s.logger.Info("next exercise selected", "request_id", ctx.Value(requestIDKey), "source", exercise.Source, "exercise_id", exercise.ID)
}
return lesson, exercise, err
}
func (s *Server) createAttempt(w http.ResponseWriter, r *http.Request) {
@@ -265,7 +301,7 @@ func (s *Server) createAttempt(w http.ResponseWriter, r *http.Request) {
return
}
exerciseID := r.FormValue("exercise_id")
exercise, err := s.store.GetExercise(r.Context(), exerciseID)
exercise, err := s.store.GetExercise(r.Context(), exerciseID, currentUserID(r))
if err != nil {
writeError(w, http.StatusNotFound, err)
return