MisConceptTutor_MS / module2.py
Jintonic92's picture
Update module2.py
f6ec0cb verified
raw
history blame
1.65 kB
import pandas as pd
import logging
from typing import Optional, Tuple
from dataclasses import dataclass
logger = logging.getLogger(__name__)
@dataclass
class GeneratedQuestion:
question: str
choices: dict
correct_answer: str
explanation: str
class SimilarQuestionGenerator:
def __init__(self, misconception_csv_path: str):
self._load_data(misconception_csv_path)
def _load_data(self, misconception_csv_path: str):
self.misconception_df = pd.read_csv(misconception_csv_path)
def get_misconception_text(self, misconception_id: float) -> Optional[str]:
if pd.isna(misconception_id):
return "No misconception provided."
row = self.misconception_df[self.misconception_df['MisconceptionId'] == int(misconception_id)]
return row.iloc[0]['MisconceptionName'] if not row.empty else "Misconception not found."
def generate_similar_question_with_text(self, construct_name, subject_name, question_text, correct_answer_text, wrong_answer_text, misconception_id) -> Tuple[Optional[GeneratedQuestion], Optional[str]]:
prompt = f"Generate a similar question for: {question_text}"
# Mock API call for demonstration
return GeneratedQuestion(question="Sample Question", choices={"A": "Option A", "B": "Option B"}, correct_answer="A", explanation="Sample Explanation"), None
def generate_similar_question(wrong_q, misconception_id, generator):
if not isinstance(wrong_q, dict):
return None
misconception_text = generator.get_misconception_text(misconception_id)
return {"question": f"Generated Question targeting {misconception_text}"}