• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

source-academy / backend / 9c2823cf899c9314fd4ccec9dd6c3b589d83e839

04 Dec 2025 05:47PM UTC coverage: 88.716% (-0.9%) from 89.621%
9c2823cf899c9314fd4ccec9dd6c3b589d83e839

push

github

web-flow
AI-powered marking (#1248)

* feat: v1 of AI-generated comments

* feat: added logging of inputs and outputs

* Update generate_ai_comments.ex

* feat: function to save outputs to database

* Format answers json before sending to LLM

* Add LLM Prompt to question params when submitting assessment xml file

* Add LLM Prompt to api response when grading view is open

* feat: added llm_prompt from qn to raw_prompt

* feat: enabling/disabling of LLM feature by course level

* feat: added llm_grading boolean field to course creation API

* feat: added api key storage in courses & edit api key/enable llm grading

* feat: encryption for llm_api_key

* feat: added final comment editing route

* feat: added logging of chosen comments

* fix: bugs when certain fields were missing

* feat: updated tests

* formatting

* fix: error handling when calling openai API

* fix: credo issues

* formatting

* Address some comments

* Fix formatting

* rm IO.inspect

* a

* Use case instead of if

* Streamlines generate_ai_comments to only send the selected question and its relevant info + use the correct llm_prompt

* Remove unncessary field

* default: false for llm_grading

* Add proper linking between ai_comments table and submissions. Return it to submission retrieval as well

* Resolve some migration comments

* Add llm_model and llm_api_url to the DB + schema

* Moves api key, api url, llm model and course prompt to course level

* Add encryption_key to env

* Do not hardcode formatting instructions

* Add Assessment level prompts to the XML

* Return some additional info for composing of prompts

* Remove un-used 'save comments'

* Fix existing assessment tests

* Fix generate_ai_comments test cases

* Fix bug preventing avengers from generating ai comments

* Fix up tests + error msgs

* Formatting

* some mix credo suggestions

* format

* Fix credo issue

* bug fix + credo fixes

* Fix tests

* format

* Modify test.exs

* Update lib/cadet_web/controllers/gener... (continued)

118 of 174 new or added lines in 9 files covered. (67.82%)

1 existing line in 1 file now uncovered.

3758 of 4236 relevant lines covered (88.72%)

7103.93 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

50.0
/lib/cadet/ai_comments.ex
1
defmodule Cadet.AIComments do
2
  @moduledoc """
3
  Handles operations related to AI comments, including creation, updates, and retrieval.
4
  """
5

6
  import Ecto.Query
7
  alias Cadet.Repo
8
  alias Cadet.AIComments.AIComment
9

10
  @doc """
11
  Creates a new AI comment log entry.
12
  """
13
  def create_ai_comment(attrs \\ %{}) do
14
    %AIComment{}
15
    |> AIComment.changeset(attrs)
16
    |> Repo.insert()
2✔
17
  end
18

19
  @doc """
20
  Gets an AI comment by ID.
21
  """
22
  def get_ai_comment(id) do
23
    case Repo.get(AIComment, id) do
1✔
NEW
24
      nil -> {:error, :not_found}
×
25
      comment -> {:ok, comment}
1✔
26
    end
27
  end
28

29
  @doc """
30
  Retrieves the latest AI comment for a specific submission and question.
31
  Returns `nil` if no comment exists.
32
  """
33
  def get_latest_ai_comment(answer_id) do
34
    Repo.one(
3✔
35
      from(c in AIComment,
36
        where: c.answer_id == ^answer_id,
37
        order_by: [desc: c.inserted_at],
38
        limit: 1
39
      )
40
    )
41
  end
42

43
  @doc """
44
  Updates the final comment for a specific submission and question.
45
  Returns the most recent comment entry for that submission/question.
46
  """
47
  def update_final_comment(answer_id, final_comment) do
NEW
48
    comment = get_latest_ai_comment(answer_id)
×
49

NEW
50
    case comment do
×
NEW
51
      nil ->
×
52
        {:error, :not_found}
53

54
      _ ->
55
        comment
56
        |> AIComment.changeset(%{final_comment: final_comment})
NEW
57
        |> Repo.update()
×
58
    end
59
  end
60

61
  @doc """
62
  Updates an existing AI comment with new attributes.
63
  """
64
  def update_ai_comment(id, attrs) do
65
    id
66
    |> get_ai_comment()
67
    |> case do
1✔
NEW
68
      {:error, :not_found} ->
×
69
        {:error, :not_found}
70

71
      {:ok, comment} ->
72
        comment
73
        |> AIComment.changeset(attrs)
74
        |> Repo.update()
1✔
75
    end
76
  end
77
end
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc