Skip to content

Commit c36903a

Browse files
jamesbrazawhitead
andauthored
Moved JSON summary prompt to mention score is an integer (#748)
Co-authored-by: Andrew White <[email protected]>
1 parent 41cfc25 commit c36903a

File tree

4 files changed

+2523
-2511
lines changed

4 files changed

+2523
-2511
lines changed

paperqa/prompts.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@
7878
"relevance_score": "..."
7979
}}
8080
81-
where `summary` is relevant information from text - {summary_length} words and `relevance_score` is the relevance of `summary` to answer question (out of 10).
81+
where `summary` is relevant information from the text - {summary_length} words. `relevance_score` is an integer 1-10 for the relevance of `summary` to the question.
8282
""" # noqa: E501
8383

8484
env_system_prompt = (

paperqa/utils.py

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -130,12 +130,19 @@ def strip_citations(text: str) -> str:
130130

131131

132132
def extract_score(text: str) -> int:
133-
# check for N/A
133+
"""
134+
Extract an integer score from the text in 0 to 10.
135+
136+
Note: score is 1-10, and we use 0 as a sentinel for not applicable.
137+
"""
138+
# Check for N/A, not applicable, not relevant.
139+
# Don't check for NA, as there can be genes containing "NA"
134140
last_line = text.split("\n")[-1]
135-
if "N/A" in last_line or "n/a" in last_line or "NA" in last_line:
136-
return 0
137-
# check for not applicable, not relevant in summary
138-
if "not applicable" in text.lower() or "not relevant" in text.lower():
141+
if (
142+
"n/a" in last_line.lower()
143+
or "not applicable" in text.lower()
144+
or "not relevant" in text.lower()
145+
):
139146
return 0
140147

141148
score = re.search(r"[sS]core[:is\s]+([0-9]+)", text)

0 commit comments

Comments
 (0)