diff --git a/app/configs/constants.py b/app/configs/constants.py index 7a7e4ea..b7be474 100644 --- a/app/configs/constants.py +++ b/app/configs/constants.py @@ -55,6 +55,7 @@ class ListeningExerciseType(str, Enum): writeBlanksQuestions = "writeBlanksQuestions" writeBlanksFill = "writeBlanksFill" writeBlanksForm = "writeBlanksForm" + trueFalse = "trueFalse" class LevelExerciseType(str, Enum): multipleChoice = "multipleChoice" diff --git a/app/services/impl/exam/listening/__init__.py b/app/services/impl/exam/listening/__init__.py index 761677d..f71afde 100644 --- a/app/services/impl/exam/listening/__init__.py +++ b/app/services/impl/exam/listening/__init__.py @@ -18,6 +18,8 @@ from .multiple_choice import MultipleChoice from .write_blank_forms import WriteBlankForms from .write_blanks import WriteBlanks from .write_blank_notes import WriteBlankNotes +from ..shared import TrueFalse + class ListeningService(IListeningService): @@ -48,6 +50,7 @@ class ListeningService(IListeningService): self._write_blanks_forms = WriteBlankForms(llm) self._write_blanks_notes = WriteBlankNotes(llm) self._import = ImportListeningModule(llm) + self._true_false = TrueFalse(llm) self._sections = { "section_1": { "topic": EducationalContent.TWO_PEOPLE_SCENARIOS, @@ -153,6 +156,12 @@ class ListeningService(IListeningService): question["variant"] = "form" self._logger.info(f"Added write blanks form: {question}") return question + elif req_exercise.type == "trueFalse": + question = await self._true_false.gen_true_false_not_given_exercise( + text, req_exercise.quantity, start_id, difficulty, "listening" + ) + self._logger.info(f"Added trueFalse: {question}") + return question # ================================================================================================================== diff --git a/app/services/impl/exam/reading/__init__.py b/app/services/impl/exam/reading/__init__.py index eb639e3..bd1d86a 100644 --- a/app/services/impl/exam/reading/__init__.py +++ b/app/services/impl/exam/reading/__init__.py @@ -10,7 +10,7 @@ from app.services.abc import IReadingService, ILLMService from .fill_blanks import FillBlanks from .idea_match import IdeaMatch from .paragraph_match import ParagraphMatch -from .true_false import TrueFalse +from ..shared import TrueFalse from .import_reading import ImportReadingModule from .write_blanks import WriteBlanks @@ -88,7 +88,7 @@ class ReadingService(IReadingService): elif req_exercise.type == "trueFalse": question = await self._true_false.gen_true_false_not_given_exercise( - text, req_exercise.quantity, start_id, difficulty + text, req_exercise.quantity, start_id, difficulty, "reading" ) self._logger.info(f"Added trueFalse: {question}") return question diff --git a/app/services/impl/exam/shared/__init__.py b/app/services/impl/exam/shared/__init__.py new file mode 100644 index 0000000..5778d99 --- /dev/null +++ b/app/services/impl/exam/shared/__init__.py @@ -0,0 +1,5 @@ +from .true_false import TrueFalse + +__all__ = [ + "TrueFalse" +] \ No newline at end of file diff --git a/app/services/impl/exam/reading/true_false.py b/app/services/impl/exam/shared/true_false.py similarity index 85% rename from app/services/impl/exam/reading/true_false.py rename to app/services/impl/exam/shared/true_false.py index 93182d5..903efe0 100644 --- a/app/services/impl/exam/reading/true_false.py +++ b/app/services/impl/exam/shared/true_false.py @@ -10,7 +10,7 @@ class TrueFalse: def __init__(self, llm: ILLMService): self._llm = llm - async def gen_true_false_not_given_exercise(self, text: str, quantity: int, start_id: int, difficulty: str): + async def gen_true_false_not_given_exercise(self, text: str, quantity: int, start_id: int, difficulty: str, module: str): messages = [ { "role": "system", @@ -41,9 +41,15 @@ class TrueFalse: for i, question in enumerate(questions, start=start_id): question["id"] = str(i) + tail = ( + "the information given in the Reading Passage" + if module == "reading" else + "what you've heard" + ) + return { "id": str(uuid.uuid4()), - "prompt": "Do the following statements agree with the information given in the Reading Passage?", + "prompt": f"Do the following statements agree with {tail}?", "questions": questions, "type": "trueFalse" }