Skip to content

Commit

Permalink
Improved json parsing (#232)
Browse files Browse the repository at this point in the history
  • Loading branch information
whitead authored Jan 30, 2024
1 parent ace5007 commit f60a79f
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 8 deletions.
4 changes: 3 additions & 1 deletion paperqa/docs.py
Original file line number Diff line number Diff line change
Expand Up @@ -701,6 +701,8 @@ async def process(match):
success = True
if self.prompts.summary_json:
try:
# fetch from markdown ```json if present
context = context.split("```json")[-1].split("```")[0]
result_data = json.loads(context)
except json.decoder.JSONDecodeError:
# fallback to string
Expand Down Expand Up @@ -758,7 +760,7 @@ async def process(match):
context_str = "\n\n".join(
[
f"{c.text.name}: {c.context}"
+ (f"\n\n Based on {c.text.doc.citation}" if detailed_citations else "")
+ (f"\n\nBased on {c.text.doc.citation}" if detailed_citations else "")
for c in answer.contexts
]
)
Expand Down
12 changes: 6 additions & 6 deletions paperqa/prompts.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,12 +59,12 @@
)

summary_json_system_prompt = """\
Respond with the following JSON format:
Provide a summary of the relevant information that could help answer the question based on the excerpt. Respond with the following JSON format:
{{
// summary relevant information from text - {summary_length} words
summary: string;
// relevance of this summary to answer question (out of 10)
relevance_score: number;
"summary": "...",
"relevance_score": "..."
}}
"""
where `summary` is relevant information from text - {summary_length} words and `relevance_score` is the relevance of `summary` to answer question (out of 10)
""" # noqa: E501
2 changes: 1 addition & 1 deletion paperqa/version.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "4.0.0-pre.5"
__version__ = "4.0.0-pre.6"

0 comments on commit f60a79f

Please sign in to comment.