Skip to content

Add AI grading statistics/feedback and refined AI comment persistence workflow#1345

Open
tzj04 wants to merge 71 commits intosource-academy:masterfrom
tzj04:feat/ai-comment-workflow
Open

Add AI grading statistics/feedback and refined AI comment persistence workflow#1345
tzj04 wants to merge 71 commits intosource-academy:masterfrom
tzj04:feat/ai-comment-workflow

Conversation

@tzj04
Copy link
Copy Markdown

@tzj04 tzj04 commented Mar 16, 2026

Summary

This PR introduces the AI comment workflow backend and LLM usage tracking end-to-end.

What Changed

  • Implemented AI comment generation controller flow.
  • Added AI comment versioning and finalization support.
  • Added comment selection support and word-level version tracking.
  • Added LLM usage logs and LLM feedback schemas.
  • Added LLM stats context and admin endpoints/views for monitoring.
  • Integrated LLM stats into assessment-related flows.
  • Refactored API by removing redundant final comment endpoint/column.
  • Refactored versioning by removing diff column generation/storage.

Backend Scope

  • Core AI comments logic:
    • lib/cadet/ai_comments.ex
    • lib/cadet/ai_comments/ai_comment.ex
    • lib/cadet/ai_comments/ai_comment_version.ex
  • LLM stats/logging:
    • lib/cadet/llm_stats.ex
    • lib/cadet/llm_stats/llm_usage_log.ex
    • lib/cadet/llm_stats/llm_feedback.ex
  • Controllers/routes/views:
    • lib/cadet_web/controllers/generate_ai_comments.ex
    • lib/cadet_web/admin_controllers/admin_llm_stats_controller.ex
    • lib/cadet_web/router.ex
  • Migrations:
    • priv/repo/migrations/20260225120000_create_ai_comment_versions.exs
    • priv/repo/migrations/20260225120001_add_fields_to_ai_comments.exs
    • priv/repo/migrations/20260303120000_create_llm_usage_logs.exs
    • priv/repo/migrations/20260303120001_create_llm_feedback.exs
    • priv/repo/migrations/20260303120002_add_question_id_to_llm_feedback.exs
    • priv/repo/migrations/20260316120000_remove_final_comment_from_ai_comment_logs.exs
    • priv/repo/migrations/20260316123000_remove_diff_columns_from_ai_comment_versions.exs

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds backend support for tracking LLM “Generate Comments” usage + collecting feedback, while updating the AI comments flow to store chosen comment indices and per-comment edit/version history. Also extends assessment aggregates to expose whether an assessment contains any LLM-enabled questions.

Changes:

  • Introduces LLMStats context + schemas, with admin endpoints for per-assessment/per-question usage stats and feedback submission/retrieval.
  • Refactors AI comment finalization to persist selected_indices, finalization metadata, and per-comment version entries (tutor edits).
  • Extends assessment aggregates with has_llm_questions and exposes isLlmGraded in assessment JSON views.

Reviewed changes

Copilot reviewed 22 out of 22 changed files in this pull request and generated 13 comments.

Show a summary per file
File Description
priv/repo/migrations/20260316123000_remove_diff_columns_from_ai_comment_versions.exs Drops unused diff columns from ai_comment_versions.
priv/repo/migrations/20260316120000_remove_final_comment_from_ai_comment_logs.exs Removes legacy final_comment column from ai_comment_logs.
priv/repo/migrations/20260303120002_add_question_id_to_llm_feedback.exs Adds question_id FK + index to llm_feedback.
priv/repo/migrations/20260303120001_create_llm_feedback.exs Creates llm_feedback table for user feedback.
priv/repo/migrations/20260303120000_create_llm_usage_logs.exs Creates llm_usage_logs table for usage events.
priv/repo/migrations/20260225120001_add_fields_to_ai_comments.exs Adds selected/finalization metadata fields to ai_comment_logs.
priv/repo/migrations/20260225120000_create_ai_comment_versions.exs Creates ai_comment_versions table for per-comment edit history.
lib/cadet/llm_stats/llm_usage_log.ex Ecto schema/changeset for usage log inserts.
lib/cadet/llm_stats/llm_feedback.ex Ecto schema/changeset for feedback inserts.
lib/cadet/llm_stats.ex Context queries for usage stats aggregation + feedback workflows.
lib/cadet/assessments/query.ex Adds has_llm_questions aggregate via JSON prompt detection.
lib/cadet/assessments/assessment.ex Adds virtual has_llm_questions field to assessment struct.
lib/cadet/ai_comments/ai_comment.ex Updates AI comment schema to new finalization fields + versions association.
lib/cadet/ai_comments/ai_comment_version.ex New schema/changeset for comment version rows.
lib/cadet/ai_comments.ex Adds APIs to save selections and create/fetch comment versions.
lib/cadet_web/views/assessments_view.ex Exposes isLlmGraded in student-facing assessment JSON.
lib/cadet_web/admin_views/admin_assessments_view.ex Exposes isLlmGraded in admin assessment JSON.
lib/cadet_web/router.ex Adds admin routes for LLM stats/feedback; updates save-chosen-comments route.
lib/cadet_web/controllers/generate_ai_comments.ex Logs usage; replaces final-comment saving with chosen-indices + edits/versioning; updates swagger docs.
lib/cadet_web/admin_controllers/admin_llm_stats_controller.ex New controller for LLM stats + feedback endpoints.
config/cadet.exs Adds an example production configuration file.
.tool-versions Adds Elixir/Erlang tool version pins.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

You can also share your feedback on Copilot code review. Take the survey.

Copy link
Copy Markdown
Member

@RichDom2185 RichDom2185 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In addition to the Copilot comments

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants