Skip to content

Commit

Permalink
store feedback quickly
Browse files Browse the repository at this point in the history
  • Loading branch information
= Enea_Gore committed Jan 16, 2025
1 parent 8452cce commit fecb88d
Show file tree
Hide file tree
Showing 7 changed files with 68 additions and 11 deletions.
2 changes: 1 addition & 1 deletion athena/athena/endpoints.py
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ def feedback_consumer(func: Union[
feedback_type = inspect.signature(func).parameters["feedbacks"].annotation.__args__[0]
module_config_type = inspect.signature(func).parameters["module_config"].annotation if "module_config" in inspect.signature(func).parameters else None

@app.post("/feed_feedbacks", responses=module_responses)
@app.post("/feedbacks", responses=module_responses)
@authenticated
@with_meta
async def wrapper(
Expand Down
Binary file added modules/text/module_text_llm/embeddings.index
Binary file not shown.
47 changes: 47 additions & 0 deletions modules/text/module_text_llm/indices.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
{
"0": {
"exercise_id": 3002,
"submission_id": 787782,
"feedbacks": [
{
"id": 6620,
"title": "Assessment of the Difference between Coupling/Cohesion",
"description": "You correctly explained the difference between coupling and cohesion, well done!",
"credits": 1.0,
"structured_grading_instruction_id": 6053,
"is_graded": null,
"meta": {},
"exercise_id": 3002,
"submission_id": 787782,
"index_start": 0,
"index_end": 722
},
{
"id": 6621,
"title": "Assessment of the Example",
"description": "Great example, well done!",
"credits": 1.0,
"structured_grading_instruction_id": 6058,
"is_graded": null,
"meta": {},
"exercise_id": 3002,
"submission_id": 787782,
"index_start": 909,
"index_end": 1299
},
{
"id": 6622,
"title": "Assessment of the Explanation why Coupling/Cohesion are important",
"description": "You correctly explained why coupling and cohesion are important, well done!",
"credits": 1.0,
"structured_grading_instruction_id": 6056,
"is_graded": null,
"meta": {},
"exercise_id": 3002,
"submission_id": 787782,
"index_start": null,
"index_end": null
}
]
}
}
2 changes: 1 addition & 1 deletion modules/text/module_text_llm/module_text_llm/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ def process_incoming_feedback(exercise: Exercise, submission: Submission, feedba
submission_id = submission.id
exercise_id = exercise.id
embedded_submission = embed_text(submission.text)
store_embedding_index(exercise_id, submission_id)
store_embedding_index(exercise_id, submission_id, feedbacks)
save_embedding(embedded_submission)

@feedback_provider
Expand Down
Empty file.
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
from llm_core.utils.predict_and_parse import predict_and_parse
from module_text_llm.helpers.utils import add_sentence_numbers, get_index_range_from_line_range, format_grading_instructions
from module_text_llm.icl_rag_approach.prompt_generate_suggestions import AssessmentModel
from module_text_llm.index_storage import retrieve_embedding_index
from module_text_llm.index_storage import retrieve_embedding_index, retrieve_feedbacks
from module_text_llm.storage_embeddings import query_embedding
from module_text_llm.generate_embeddings import embed_text
from athena.text import get_stored_feedback
Expand Down Expand Up @@ -47,10 +47,12 @@ async def generate_suggestions(exercise: Exercise, submission: Submission, confi
for index in list_of_indices[0]:
if index != -1:
exercise_id, submission_id = retrieve_embedding_index(list_of_indices)
stored_feedback = list(get_stored_feedback(exercise_id, submission_id))
stored_feedback = retrieve_feedbacks(index) # -> List[Feedback]
# stored_feedback = list(get_stored_feedback(exercise_id, submission_id))
logger.info("Stored feedback:")
for feedback_item in stored_feedback:
logger.info("- %s", feedback_item)
if stored_feedback is not None:
for feedback_item in stored_feedback:
logger.info("- %s", feedback_item)

logger.info("Stored submission:")
rag_context.append({"submission": submission.text, "feedback": stored_feedback})
Expand Down
18 changes: 13 additions & 5 deletions modules/text/module_text_llm/module_text_llm/index_storage.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import json
import os

INDEX_FILE = "indices.json"

def load_indices():
Expand All @@ -10,15 +9,15 @@ def load_indices():
return json.load(f)
else:
return {}

def store_embedding_index(exercise_id, submission_id):
def store_embedding_index(exercise_id, submission_id,feedbacks):
""" Store a new submission and exercise ID with an auto-incrementing index. """
indices = load_indices()
next_index = len(indices)

indices[next_index] = {
"exercise_id": exercise_id,
"submission_id": submission_id
"submission_id": submission_id,
"feedbacks": [feedback.dict() for feedback in feedbacks]
}

with open(INDEX_FILE, 'w', encoding="utf-8") as f:
Expand All @@ -34,3 +33,12 @@ def retrieve_embedding_index(index):
return indices[index]["exercise_id"], indices[index]["submission_id"]

return None, None

def retrieve_feedbacks(index):
index = str(index)
indices = load_indices()

if index in indices:
return indices[index]["feedbacks"]

return None

0 comments on commit fecb88d

Please sign in to comment.