From 84f13ea32c22b85924cd681a4b5f4fbd174afd71 Mon Sep 17 00:00:00 2001 From: Andrew White Date: Wed, 6 Dec 2023 20:06:11 -0800 Subject: [PATCH] Fixed another markdown bug --- paperqa/types.py | 4 +++- paperqa/version.py | 2 +- tests/test_paperqa.py | 24 +++++++++++++++++++++--- 3 files changed, 25 insertions(+), 5 deletions(-) diff --git a/paperqa/types.py b/paperqa/types.py index 60f4c3c8..f468d657 100644 --- a/paperqa/types.py +++ b/paperqa/types.py @@ -12,6 +12,8 @@ except ImportError: from pydantic import BaseModel, validator +import re + from .prompts import ( citation_prompt, default_system_prompt, @@ -146,7 +148,7 @@ def markdown(self) -> Tuple[str, str]: for citation in iter_citations(self.answer): compound = "" strip = True - for c in citation.split(",;"): + for c in re.split(",|;", citation): c = c.strip("() ") if c == "Extra background information": continue diff --git a/paperqa/version.py b/paperqa/version.py index b15beac2..5de4250b 100644 --- a/paperqa/version.py +++ b/paperqa/version.py @@ -1 +1 @@ -__version__ = "3.13.4" +__version__ = "3.13.5" diff --git a/tests/test_paperqa.py b/tests/test_paperqa.py index b0dd9536..75526880 100644 --- a/tests/test_paperqa.py +++ b/tests/test_paperqa.py @@ -131,7 +131,8 @@ def test_markdown(): answer = Answer( question="What was Fredic's greatest accomplishment?", answer="Frederick Bates's greatest accomplishment was his role in resolving land disputes " - "and his service as governor of Missouri (Wiki2023 chunk 1). It is said (in 2010) that foo.", + "and his service as governor of Missouri (Wiki2023 chunk 1, Wiki2023 chunk 2). It is said (in 2010) that foo." + "However many dispute this (Wiki2023 chunk 1).", contexts=[ Context( context="", @@ -147,12 +148,29 @@ def test_markdown(): ), ), score=5, - ) + ), + Context( + context="", + text=Text( + text="It is said (in 2010) that foo.", + name="Wiki2023 chunk 2", + doc=Doc( + name="Wiki2023", + docname="Wiki2023", + citation="WikiMedia Foundation, 2023, Accessed now", + texts=[], + ), + ), + score=5, + ), ], ) m, r = answer.markdown() - print(r) + assert len(r.split("\n")) == 2 + assert "[^2]" in m + assert "[^3]" not in m assert "[^1]" in m + print(m, r) answer = answer.combine_with(answer) m2, r2 = answer.markdown() assert m2.startswith(m)