-
Notifications
You must be signed in to change notification settings - Fork 56
AI-powered marking #1248
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
xxdydx
wants to merge
39
commits into
master
Choose a base branch
from
feat/add-AI-generated-comments-grading
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
AI-powered marking #1248
Changes from all commits
Commits
Show all changes
39 commits
Select commit
Hold shift + click to select a range
5cd6ac6
feat: v1 of AI-generated comments
xxdydx 853ba84
feat: added logging of inputs and outputs
xxdydx 4c37d14
Update generate_ai_comments.ex
xxdydx 8192b3d
feat: function to save outputs to database
xxdydx 8a235b3
Format answers json before sending to LLM
EugeneOYZ1203n d384e06
Add LLM Prompt to question params when submitting assessment xml file
EugeneOYZ1203n 98feac2
Add LLM Prompt to api response when grading view is open
EugeneOYZ1203n 7716d57
feat: added llm_prompt from qn to raw_prompt
xxdydx df34dbd
feat: enabling/disabling of LLM feature by course level
xxdydx 0a25fa8
feat: added llm_grading boolean field to course creation API
xxdydx 2723f5a
feat: added api key storage in courses & edit api key/enable llm grading
xxdydx 02f7ed1
feat: encryption for llm_api_key
xxdydx cb34984
feat: added final comment editing route
xxdydx 09a7b09
feat: added logging of chosen comments
xxdydx ed44a7e
fix: bugs when certain fields were missing
xxdydx 3715368
feat: updated tests
xxdydx 5bfe276
formatting
xxdydx c27b93b
Merge branch 'master' into feat/add-AI-generated-comments-grading
xxdydx 17884fd
fix: error handling when calling openai API
xxdydx f91cc92
fix: credo issues
xxdydx 81e5bf7
formatting
xxdydx 8f8b93a
Merge branch 'master' into feat/add-AI-generated-comments-grading
RichDom2185 1ec67d7
Address some comments
Tkaixiang 4f2af5d
Fix formatting
Tkaixiang ec67aa3
rm IO.inspect
Tkaixiang 11ff272
a
Tkaixiang 1a77f67
Use case instead of if
Tkaixiang 02922e9
Streamlines generate_ai_comments to only send the selected question a…
Tkaixiang f068aa9
Remove unncessary field
Tkaixiang 5f3ad2c
default: false for llm_grading
Tkaixiang 34d326c
Add proper linking between ai_comments table and submissions. Return …
Tkaixiang 6ff2864
Resolve some migration comments
Tkaixiang 0854822
Add llm_model and llm_api_url to the DB + schema
Tkaixiang f0ccaf6
Moves api key, api url, llm model and course prompt to course level
Tkaixiang d14c03e
Add encryption_key to env
Tkaixiang c345e03
Do not hardcode formatting instructions
Tkaixiang b782641
Add Assessment level prompts to the XML
Tkaixiang c4defb9
Return some additional info for composing of prompts
Tkaixiang 04590f4
Remove un-used 'save comments'
Tkaixiang File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -118,3 +118,6 @@ erl_crash.dump | |
|
||
# Generated lexer | ||
/src/source_lexer.erl | ||
|
||
# Ignore log files | ||
/log |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
defmodule Cadet.AIComments do | ||
@moduledoc """ | ||
Handles operations related to AI comments, including creation, updates, and retrieval. | ||
""" | ||
|
||
import Ecto.Query | ||
alias Cadet.Repo | ||
alias Cadet.AIComments.AIComment | ||
|
||
@doc """ | ||
Creates a new AI comment log entry. | ||
""" | ||
def create_ai_comment(attrs \\ %{}) do | ||
%AIComment{} | ||
|> AIComment.changeset(attrs) | ||
|> Repo.insert() | ||
end | ||
|
||
@doc """ | ||
Gets an AI comment by ID. | ||
""" | ||
def get_ai_comment(id) do | ||
case Repo.get(AIComment, id) do | ||
nil -> {:error, :not_found} | ||
comment -> {:ok, comment} | ||
end | ||
end | ||
|
||
@doc """ | ||
Retrieves an AI comment for a specific submission and question. | ||
Returns `nil` if no comment exists. | ||
""" | ||
def get_ai_comments_for_submission(submission_id, question_id) do | ||
Repo.one( | ||
from(c in AIComment, | ||
where: c.submission_id == ^submission_id and c.question_id == ^question_id | ||
) | ||
) | ||
end | ||
|
||
@doc """ | ||
Retrieves the latest AI comment for a specific submission and question. | ||
Returns `nil` if no comment exists. | ||
""" | ||
def get_latest_ai_comment(submission_id, question_id) do | ||
Repo.one( | ||
from(c in AIComment, | ||
where: c.submission_id == ^submission_id and c.question_id == ^question_id, | ||
order_by: [desc: c.inserted_at], | ||
limit: 1 | ||
) | ||
) | ||
end | ||
|
||
@doc """ | ||
Updates the final comment for a specific submission and question. | ||
Returns the most recent comment entry for that submission/question. | ||
""" | ||
def update_final_comment(submission_id, question_id, final_comment) do | ||
comment = get_latest_ai_comment(submission_id, question_id) | ||
|
||
case comment do | ||
nil -> | ||
{:error, :not_found} | ||
|
||
_ -> | ||
comment | ||
|> AIComment.changeset(%{final_comment: final_comment}) | ||
|> Repo.update() | ||
end | ||
end | ||
|
||
@doc """ | ||
Updates an existing AI comment with new attributes. | ||
""" | ||
def update_ai_comment(id, attrs) do | ||
id | ||
|> get_ai_comment() | ||
|> case do | ||
{:error, :not_found} -> | ||
{:error, :not_found} | ||
|
||
{:ok, comment} -> | ||
comment | ||
|> AIComment.changeset(attrs) | ||
|> Repo.update() | ||
end | ||
end | ||
|
||
@doc """ | ||
Updates the chosen comments for a specific submission and question. | ||
Accepts an array of comments and replaces the existing array in the database. | ||
""" | ||
def update_chosen_comments(submission_id, question_id, new_comments) do | ||
comment = get_latest_ai_comment(submission_id, question_id) | ||
|
||
case comment do | ||
nil -> | ||
{:error, :not_found} | ||
|
||
_ -> | ||
comment | ||
|> AIComment.changeset(%{comment_chosen: new_comments}) | ||
|> Repo.update() | ||
end | ||
end | ||
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
defmodule Cadet.AIComments.AIComment do | ||
@moduledoc """ | ||
Defines the schema and changeset for AI comments. | ||
""" | ||
|
||
use Ecto.Schema | ||
import Ecto.Changeset | ||
|
||
schema "ai_comment_logs" do | ||
field(:raw_prompt, :string) | ||
field(:answers_json, :string) | ||
field(:response, :string) | ||
field(:error, :string) | ||
field(:comment_chosen, {:array, :string}) | ||
field(:final_comment, :string) | ||
|
||
belongs_to(:submission, Cadet.Assessments.Submission) | ||
belongs_to(:question, Cadet.Assessments.Question) | ||
|
||
timestamps() | ||
end | ||
|
||
def changeset(ai_comment, attrs) do | ||
ai_comment | ||
|> cast(attrs, [ | ||
:submission_id, | ||
:question_id, | ||
:raw_prompt, | ||
:answers_json, | ||
:response, | ||
:error, | ||
:comment_chosen, | ||
:final_comment | ||
]) | ||
|> validate_required([:submission_id, :question_id, :raw_prompt, :answers_json]) | ||
|> foreign_key_constraint(:submission_id) | ||
|> foreign_key_constraint(:question_id) | ||
end | ||
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.