Skip to content

Commit

Permalink
Refactor grading criterion handling: remove structured grading criter…
Browse files Browse the repository at this point in the history
…ion model, update imports
  • Loading branch information
LeonWehrhahn committed Dec 7, 2024
1 parent 0eff118 commit 672f762
Show file tree
Hide file tree
Showing 8 changed files with 10 additions and 76 deletions.
2 changes: 1 addition & 1 deletion athena/athena/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,4 +69,4 @@ async def validation_exception_handler(request: Request, exc: RequestValidationE
return JSONResponse(
status_code=422,
content={"detail": exc.errors()},
)
)
2 changes: 0 additions & 2 deletions athena/athena/models/db_exercise.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@ class DBExercise(Model, Base):
grading_criteria = Column(JSON, nullable=True)
meta = Column(JSON, nullable=False)

structured_grading_criterion = relationship("DBStructuredGradingCriterion", back_populates="exercise", uselist=False) # Use uselist=False for one-to-one

# Polymorphism, discriminator attribute
type = Column(SqlEnum(ExerciseType), index=True, nullable=False)

Expand Down
3 changes: 1 addition & 2 deletions athena/athena/schemas/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,4 @@
from .modeling_feedback import ModelingFeedback
from .modeling_exercise import ModelingExercise
from .modeling_submission import ModelingSubmission
from .grading_criterion import GradingCriterion, StructuredGradingInstruction
from .structured_grading_criterion import StructuredGradingCriterion
from .grading_criterion import GradingCriterion, StructuredGradingInstruction, StructuredGradingCriterion
5 changes: 4 additions & 1 deletion athena/athena/schemas/grading_criterion.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,7 @@ class GradingCriterion(Schema, ABC):
title: Optional[str] = Field(None, example="Some instructions")
structured_grading_instructions: List[StructuredGradingInstruction] = Field(
[], example=[{"credits": 1.0, "gradingScale": "Good", "instructionDescription": "Some instructions", "feedback": "Nicely done!", "usageCount": 1},
{"credits": 0.0, "gradingScale": "Bad", "instructionDescription": "Some instructions", "feedback": "Try again!", "usageCount": 0}])
{"credits": 0.0, "gradingScale": "Bad", "instructionDescription": "Some instructions", "feedback": "Try again!", "usageCount": 0}])

class StructuredGradingCriterion(BaseModel):
criteria: List[GradingCriterion]
7 changes: 0 additions & 7 deletions athena/athena/schemas/structured_grading_criterion.py

This file was deleted.

31 changes: 0 additions & 31 deletions athena/athena/storage/structured_grading_criterion_storage.py

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from athena.schemas.structured_grading_criterion import StructuredGradingCriterion
from athena.schemas.grading_criterion import StructuredGradingCriterion
from langchain_core.output_parsers import PydanticOutputParser
from langchain_core.prompts import ChatPromptTemplate

Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,9 @@
import hashlib
import json
from typing import Any, Dict, List, Optional
from athena import logger
from typing import List, Optional
from athena.metadata import emit_meta
from athena.storage.structured_grading_criterion_storage import get_structured_grading_criterion, store_structured_grading_criterion
from langchain_core.output_parsers import PydanticOutputParser
from langchain_core.prompts import ChatPromptTemplate

from athena.schemas import GradingCriterion, StructuredGradingCriterion
from athena.schemas.grading_criterion import GradingCriterion, StructuredGradingCriterion
from llm_core.utils.predict_and_parse import predict_and_parse
from module_modeling_llm.config import BasicApproachConfig
from module_modeling_llm.models.exercise_model import ExerciseModel
Expand All @@ -23,13 +19,6 @@ async def get_structured_grading_instructions(

if grading_criteria:
return StructuredGradingCriterion(criteria=grading_criteria)

# Check if we have cached instructions for this exercise
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([
("system", config.generate_suggestions_prompt.structured_grading_instructions_system_message),
Expand Down Expand Up @@ -64,22 +53,5 @@ async def get_structured_grading_instructions(

if not grading_instruction_result:
raise ValueError("No structured grading instructions were returned by the model.")

# Cache the grading instructions
hash = get_grading_instructions_hash(exercise_model)
store_structured_grading_criterion(exercise_model.exercise_id, hash, grading_instruction_result)

return grading_instruction_result

def get_grading_instructions_hash(exercise: ExerciseModel) -> str:

hashable_data = {
"problem_statement": exercise.problem_statement,
"grading_instructions": exercise.grading_instructions,
"sample_solution": exercise.transformed_example_solution,
"max_points": exercise.max_points,
"bonus_points": exercise.bonus_points,
}

json_string = json.dumps(hashable_data, sort_keys=True, default=str)
return hashlib.sha256(json_string.encode()).hexdigest()
return grading_instruction_result

0 comments on commit 672f762

Please sign in to comment.