Skip to content

Commit

Permalink
some more files
Browse files Browse the repository at this point in the history
  • Loading branch information
semio committed Oct 14, 2023
1 parent 3339a12 commit 0dac683
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 0 deletions.
53 changes: 53 additions & 0 deletions yival_experiments/question_reader.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
from typing import Iterator, List

from question_reader_config import QuestionReaderConfig
from yival.data.base_reader import BaseReader
from yival.schemas.common_structures import InputData

from lib.pilot.helpers import read_ai_eval_spreadsheet, get_questions


class QuestionReader(BaseReader):
"""
QuestionReader is ...
Attributes:
config (TXTReaderConfig): Configuration object specifying reader parameters.
Methods:
__init__(self, config: TXTReaderConfig): Initializes the TXTReader with
a given configuration.
read(self, path: str) -> Iterator[List[InputData]]: Reads the TXT file
and yields chunks of InputData.
"""

config: QuestionReaderConfig
default_config = QuestionReaderConfig()

def __init__(self, config: QuestionReaderConfig):
super().__init__(config)
self.config = config

def read(self, path: str) -> Iterator[List[InputData]]:
sheet = read_ai_eval_spreadsheet()
questions = get_questions(sheet)

for q, opts in questions:
options_text = [f"{opt.letter}. {opt.question_option}" for opt in opts]
content = {
"question_id": q.question_id,
"question_text": q.published_version_of_question,
"options_text": options_text,
}
correct_answer = list(
filter(lambda x: x.correctness_of_answer_option == 1, opts)
)[0]
expected_result = (
f"{correct_answer.letter}. {correct_answer.question_option}"
)

example_id = self.generate_example_id({"content": content}, "")
input_data_instance = InputData(
example_id=example_id, content=content, expected_result=expected_result
)
yield [input_data_instance]
12 changes: 12 additions & 0 deletions yival_experiments/question_reader_config.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
from dataclasses import asdict, dataclass
from yival.data.base_reader import BaseReaderConfig


@dataclass
class QuestionReaderConfig(BaseReaderConfig):
"""
Configuration specific to the questions reader.
"""

def asdict(self):
return asdict(self)

0 comments on commit 0dac683

Please sign in to comment.