Skip to content

Commit 68af519

Browse files
authored
Fixing used_images usage in summary_json_system_prompt (#1109)
1 parent 0effe2e commit 68af519

File tree

3 files changed

+24
-4
lines changed

3 files changed

+24
-4
lines changed

README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -751,6 +751,12 @@ When creating contextual summaries on a given chunk (a `Text`),
751751
the summary LLM is passed both the chunk's text and the chunk's associated media,
752752
but the output contextual summary itself remains text-only.
753753

754+
If you would like,
755+
specifying the prompt `paperqa.prompts.summary_json_multimodal_system_prompt`
756+
to the setting `prompt.summary_json_system`
757+
will include a `used_images` flag attributing
758+
usage of images in any contextual summarizations.
759+
754760
### Using External DB/Vector DB and Caching
755761

756762
You may want to cache parsed texts and embeddings in an external database or file.

src/paperqa/prompts.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,19 @@
112112
" Your summary, combined with many others,"
113113
" will be given to the model to generate an answer."
114114
" Respond with the following JSON format:"
115-
'\n\n{{\n "summary": "...",\n "relevance_score": 0-10,\n "used_images"\n}}'
115+
'\n\n{{\n "summary": "...",\n "relevance_score": 0-10\n}}'
116+
"\n\nwhere `summary` is relevant information from the text - {summary_length} words."
117+
" `relevance_score` is an integer 0-10 for the relevance of `summary` to the question."
118+
"\n\nThe excerpt may or may not contain relevant information."
119+
" If not, leave `summary` empty, and make `relevance_score` be 0."
120+
)
121+
summary_json_multimodal_system_prompt = (
122+
"Provide a summary of the relevant information"
123+
" that could help answer the question based on the excerpt."
124+
" Your summary, combined with many others,"
125+
" will be given to the model to generate an answer."
126+
" Respond with the following JSON format:"
127+
'\n\n{{\n "summary": "...",\n "relevance_score": 0-10,\n "used_images": "..."\n}}'
116128
"\n\nwhere `summary` is relevant information from the text - {summary_length} words."
117129
" `relevance_score` is an integer 0-10 for the relevance of `summary` to the question."
118130
" `used_images` is a boolean flag indicating"

tests/test_paperqa.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@
6161
llm_parse_json,
6262
map_fxn_summary,
6363
)
64-
from paperqa.prompts import CANNOT_ANSWER_PHRASE
64+
from paperqa.prompts import CANNOT_ANSWER_PHRASE, summary_json_multimodal_system_prompt
6565
from paperqa.prompts import qa_prompt as default_qa_prompt
6666
from paperqa.readers import PDFParserFn, parse_image, read_doc
6767
from paperqa.settings import AsyncContextSerializer
@@ -1594,6 +1594,7 @@ async def test_images(stub_data_dir: Path) -> None:
15941594
# We don't support image embeddings yet, so disable embedding
15951595
settings.answer.evidence_retrieval = False
15961596
settings.parsing.defer_embedding = True
1597+
settings.prompts.summary_json_system = summary_json_multimodal_system_prompt
15971598

15981599
docs = Docs()
15991600
districts_docname = await docs.aadd(
@@ -1625,7 +1626,7 @@ async def test_images(stub_data_dir: Path) -> None:
16251626
if c.id in session.used_contexts and c.text.doc == districts_doc
16261627
]
16271628
assert contexts_used
1628-
assert all(c.used_images for c in contexts_used) # type: ignore[attr-defined]
1629+
assert all(bool(c.used_images) for c in contexts_used) # type: ignore[attr-defined]
16291630

16301631

16311632
@pytest.mark.asyncio
@@ -1636,6 +1637,7 @@ async def test_images_corrupt(stub_data_dir: Path) -> None:
16361637
# We don't support image embeddings yet, so disable embedding
16371638
settings.answer.evidence_retrieval = False
16381639
settings.parsing.defer_embedding = True
1640+
settings.prompts.summary_json_system = summary_json_multimodal_system_prompt
16391641

16401642
docs = Docs()
16411643
districts_docname = await docs.aadd(
@@ -1687,7 +1689,7 @@ async def test_images_corrupt(stub_data_dir: Path) -> None:
16871689
if c.id in session.used_contexts and c.text.doc == districts_doc
16881690
]
16891691
assert contexts_used
1690-
assert all(not c.used_images for c in contexts_used) # type: ignore[attr-defined]
1692+
assert all(not bool(c.used_images) for c in contexts_used) # type: ignore[attr-defined]
16911693

16921694

16931695
def test_zotero() -> None:

0 commit comments

Comments
 (0)