Skip to content

Commit 71665c4

Browse files
Automate fetching the current year (#828)
1 parent b67846d commit 71665c4

File tree

3 files changed

+16
-28
lines changed

3 files changed

+16
-28
lines changed

paperqa/prompts.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
from datetime import datetime
2+
13
summary_prompt = (
24
"Summarize the excerpt below to help answer a question.\n\nExcerpt from"
35
" {citation}\n\n----\n\n{text}\n\n----\n\nQuestion: {question}\n\nDo not directly"
@@ -47,10 +49,11 @@
4749
"Papers: {papers}\n\n"
4850
"Selected keys:"
4951
)
52+
5053
citation_prompt = (
5154
"Provide the citation for the following text in MLA Format. "
5255
"Do not write an introductory sentence. "
53-
"If reporting date accessed, the current year is 2024\n\n"
56+
f"If reporting date accessed, the current year is {datetime.now().year}\n\n"
5457
"{text}\n\n"
5558
"Citation:"
5659
)

tests/test_configs.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
from pydantic import ValidationError
66
from pytest_subtests import SubTests
77

8+
from paperqa.prompts import citation_prompt
89
from paperqa.settings import (
910
AgentSettings,
1011
IndexSettings,
@@ -15,6 +16,7 @@
1516
get_settings,
1617
)
1718
from paperqa.types import Doc, DocDetails
19+
from paperqa.utils import get_year
1820

1921

2022
def test_prompt_settings_validation() -> None:
@@ -167,3 +169,11 @@ def test_o1_requires_temp_equals_1() -> None:
167169
def test_matches_filter_criteria(doc_class, doc_data, filter_criteria, expected_result):
168170
doc = doc_class(**doc_data)
169171
assert doc.matches_filter_criteria(filter_criteria) == expected_result
172+
173+
174+
def test_citation_prompt_current_year():
175+
expected_year_text = f"the current year is {get_year()}"
176+
177+
assert (
178+
expected_year_text in citation_prompt
179+
), f"Citation prompt should contain '{expected_year_text}' but got: {citation_prompt}"

uv.lock

Lines changed: 2 additions & 27 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)