Skip to content

Commit

Permalink
fix: improve logging of parser errors (#745)
Browse files Browse the repository at this point in the history
  • Loading branch information
MartinBernstorff authored Oct 27, 2024
1 parent 1bf2b38 commit 6a101d4
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
6 changes: 5 additions & 1 deletion memium/source/extractors/extractor_qa.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,13 +53,14 @@ def extract_prompts(self, document: Document) -> Sequence[QAPrompt]:
blocks = self._string_to_blocks_by_newlines(document.content)
block_starting_line_nr = 1

missing_answers: list[str] = []
for block_string in blocks:
if self._has_qa(block_string):
question = self._get_first_question(block_string)
try:
answer = self._get_first_answer(block_string)
except IndexError:
logging.warning(f"Could not find answer in {document.title} for {question}")
missing_answers.append(f"{document.title}: {question}")
continue

prompts.append(
Expand All @@ -74,4 +75,7 @@ def extract_prompts(self, document: Document) -> Sequence[QAPrompt]:
block_lines = len(re.findall(r"\n", block_string, flags=re.DOTALL))
block_starting_line_nr += block_lines

if missing_answers:
logging.warning(f"{missing_answers} is missing an answer")

return prompts
7 changes: 6 additions & 1 deletion memium/source/prompt_source.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,12 @@ def _deduplicate_group(self, group: tuple[str, Sequence[BasePrompt]]) -> BasePro
prompts_in_group = group[1]

if len(prompts_in_group) != 1:
log.warning(f"Found duplicate prompts for {prompts_in_group[0]}")
identifier = (
prompts_in_group[0].edit_url
if prompts_in_group[0].edit_url
else prompts_in_group[0]
)
log.warning(f"Found duplicate prompts for {identifier}. Prompts: {prompts_in_group}")

return prompts_in_group[0]

Expand Down

0 comments on commit 6a101d4

Please sign in to comment.