Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixing crash when json.loads returns str #248

Merged
merged 1 commit into from
Mar 8, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 5 additions & 7 deletions paperqa/docs.py
Original file line number Diff line number Diff line change
Expand Up @@ -708,17 +708,15 @@ async def process(match):
except json.decoder.JSONDecodeError:
# fallback to string
success = False
else:
success = isinstance(result_data, dict)
if success:
try:
context = result_data["summary"]
score = result_data["relevance_score"]
del result_data["summary"]
del result_data["relevance_score"]
if "question" in result_data:
del result_data["question"]
context = result_data.pop("summary")
score = result_data.pop("relevance_score")
result_data.pop("question", None)
extras = result_data
except KeyError:
# fallback
success = False
# fallback to string (or json mode not enabled)
if not success or not self.prompts.summary_json:
Expand Down
Loading