Skip to content

Commit

Permalink
Fixed another markdown bug
Browse files Browse the repository at this point in the history
  • Loading branch information
whitead committed Dec 7, 2023
1 parent 97a99b7 commit 84f13ea
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 5 deletions.
4 changes: 3 additions & 1 deletion paperqa/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
except ImportError:
from pydantic import BaseModel, validator

import re

from .prompts import (
citation_prompt,
default_system_prompt,
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion paperqa/version.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "3.13.4"
__version__ = "3.13.5"
24 changes: 21 additions & 3 deletions tests/test_paperqa.py
Original file line number Diff line number Diff line change
Expand Up @@ -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="",
Expand All @@ -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)
Expand Down

0 comments on commit 84f13ea

Please sign in to comment.