Skip to content

Commit

Permalink
Refactor exercise storage and structured grading criterion handling; …
Browse files Browse the repository at this point in the history
…remove debug prints, update caching logic, and change serialization method for structured grading instructions
  • Loading branch information
LeonWehrhahn committed Dec 6, 2024
1 parent fda3f13 commit a83ac8b
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 13 deletions.
3 changes: 0 additions & 3 deletions athena/athena/storage/exercise_storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,10 @@ def store_exercises(exercises: List[Exercise], lms_url: Optional[str] = None):
if lms_url is None:
lms_url = get_lms_url()

print("Exercise lms_url 2: ", lms_url, "\n\n\n\n")

with get_db() as db:
for e in exercises:
exercise_model = e.to_model()
exercise_model.lms_url = lms_url
print("Exercise model: ", exercise_model.lms_url, "\n\n\n\n")
db.merge(exercise_model)
db.commit()

Expand Down
19 changes: 9 additions & 10 deletions athena/athena/storage/structured_grading_criterion_storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,14 @@
from athena.schemas import StructuredGradingCriterion

def get_structured_grading_criterion(exercise_id: int, current_hash: Optional[str] = None) -> Optional[StructuredGradingCriterion]:
lms_url = get_lms_url()
with get_db() as db:
cache_entry = db.query(DBStructuredGradingCriterion).filter_by(
exercise_id=exercise_id, lms_url=lms_url
).first()
if cache_entry is not None and (current_hash is None or cache_entry.instructions_hash.is_(current_hash)):
return StructuredGradingCriterion.parse_raw(cache_entry.cached_instructions)

return None
lms_url = get_lms_url()
with get_db() as db:
cache_entry = db.query(DBStructuredGradingCriterion).filter_by(
exercise_id=exercise_id, lms_url=lms_url
).first()
if cache_entry is not None and (current_hash is None or cache_entry.instructions_hash == current_hash): # type: ignore
return StructuredGradingCriterion.parse_obj(cache_entry.structured_grading_criterion)
return None

def store_structured_grading_criterion(
exercise_id: int, hash: str, structured_instructions: StructuredGradingCriterion
Expand All @@ -26,7 +25,7 @@ def store_structured_grading_criterion(
exercise_id=exercise_id,
lms_url=lms_url,
instructions_hash=hash,
cached_instructions=structured_instructions.json(),
structured_grading_criterion=structured_instructions.dict(),
)
)
db.commit()
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ async def get_structured_grading_instructions(
current_hash = get_grading_instructions_hash(exercise_model)
cached_instructions = get_structured_grading_criterion(exercise_model.exercise_id, current_hash)
if cached_instructions:
print("Using cached instructions")
return cached_instructions

chat_prompt = ChatPromptTemplate.from_messages([
Expand Down

0 comments on commit a83ac8b

Please sign in to comment.