änderungen von vorherigen Codexnutzung: sollte den Agent lassen die Aufgaben zu erzeugen
This commit is contained in:
@@ -22,6 +22,7 @@ type DataStore interface {
|
||||
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)
|
||||
SaveGeneratedExercise(ctx context.Context, userID string, generated domain.GeneratedExercise) (domain.Lesson, domain.Exercise, error)
|
||||
GetExercise(ctx context.Context, id 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)
|
||||
@@ -189,7 +190,7 @@ func (s *Server) dashboard(w http.ResponseWriter, r *http.Request) {
|
||||
writeError(w, http.StatusInternalServerError, err)
|
||||
return
|
||||
}
|
||||
lesson, exercise, err := s.store.NextLessonAndExercise(r.Context(), profile)
|
||||
lesson, exercise, err := s.nextAgentExercise(r.Context(), user, profile, progress)
|
||||
if err != nil {
|
||||
writeError(w, http.StatusNotFound, err)
|
||||
return
|
||||
@@ -209,12 +210,23 @@ func (s *Server) progress(w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
|
||||
func (s *Server) nextLesson(w http.ResponseWriter, r *http.Request) {
|
||||
profile, err := s.store.GetPrimaryProfile(r.Context(), currentUserID(r))
|
||||
userID := currentUserID(r)
|
||||
user, err := s.store.GetUser(r.Context(), userID)
|
||||
if err != nil {
|
||||
writeError(w, http.StatusNotFound, err)
|
||||
return
|
||||
}
|
||||
lesson, exercise, err := s.store.NextLessonAndExercise(r.Context(), profile)
|
||||
profile, err := s.store.GetPrimaryProfile(r.Context(), userID)
|
||||
if err != nil {
|
||||
writeError(w, http.StatusNotFound, err)
|
||||
return
|
||||
}
|
||||
progress, err := s.store.Progress(r.Context(), userID, 10)
|
||||
if err != nil {
|
||||
writeError(w, http.StatusInternalServerError, err)
|
||||
return
|
||||
}
|
||||
lesson, exercise, err := s.nextAgentExercise(r.Context(), user, profile, progress)
|
||||
if err != nil {
|
||||
writeError(w, http.StatusNotFound, err)
|
||||
return
|
||||
@@ -222,6 +234,31 @@ 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) {
|
||||
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",
|
||||
})
|
||||
if err == nil && generated.Source == "flowise" && strings.TrimSpace(generated.ReferenceText) != "" {
|
||||
lesson, exercise, saveErr := s.store.SaveGeneratedExercise(ctx, user.ID, generated)
|
||||
if saveErr == nil {
|
||||
return lesson, exercise, nil
|
||||
}
|
||||
s.logger.Warn("saving generated exercise failed, using seed fallback", "error", saveErr)
|
||||
}
|
||||
if err != nil {
|
||||
s.logger.Warn("flowise next exercise failed, using seed fallback", "error", err)
|
||||
}
|
||||
return s.store.NextLessonAndExercise(ctx, profile)
|
||||
}
|
||||
|
||||
func (s *Server) createAttempt(w http.ResponseWriter, r *http.Request) {
|
||||
if err := r.ParseMultipartForm(24 << 20); err != nil {
|
||||
writeError(w, http.StatusBadRequest, err)
|
||||
@@ -372,6 +409,14 @@ func firstNonEmpty(values ...string) string {
|
||||
return ""
|
||||
}
|
||||
|
||||
func flowiseSessionID(userID, targetLanguage, scope string) string {
|
||||
parts := []string{strings.TrimSpace(userID), strings.TrimSpace(targetLanguage), strings.TrimSpace(scope)}
|
||||
for i, part := range parts {
|
||||
parts[i] = strings.ReplaceAll(part, " ", "_")
|
||||
}
|
||||
return strings.Join(parts, ":")
|
||||
}
|
||||
|
||||
func valueOr(value, fallback string) string {
|
||||
if strings.TrimSpace(value) == "" {
|
||||
return fallback
|
||||
|
||||
Reference in New Issue
Block a user