Skip to content

Commit 8f8cfba

Browse files
committed
Updated prompts a bit
1 parent 4cec515 commit 8f8cfba

File tree

3 files changed

+12
-10
lines changed

3 files changed

+12
-10
lines changed

README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -52,17 +52,17 @@ Make sure you have set your OPENAI_API_KEY environment variable to your [openai
5252

5353
To use paper-qa, you need to have a list of paths (valid extensions include: .pdf, .txt) and a list of citations (strings) that correspond to the paths. You can then use the `Docs` class to add the documents and then query them.
5454

55-
*This uses a lot of tokens!! About 5-10k tokens per answer + embedding cost (negligible unless many documents used). That is up to $0.20 per answer with current GPT-3 pricing. Use wisely.*
55+
*This uses a lot of tokens!! About 5-10k tokens per answer + embedding cost (negligible unless many documents used). That is up to $0.02 per answer with current GPT-3 pricing. Use wisely.*
5656

5757
```python
5858

5959
from paperqa import Docs
6060

61-
# get a list of paths, citations
61+
# get a list of paths
6262

6363
docs = Docs()
64-
for d, c in zip(my_docs, my_citations):
65-
docs.add(d, c)
64+
for d in my_docs:
65+
docs.add(d)
6666

6767
# takes ~ 1 min and costs $0.10-$0.20 to execute this line
6868
answer = docs.query("What manufacturing challenges are unique to bispecific antibodies?")

paperqa/docs.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
from langchain.callbacks import get_openai_callback
2323
from langchain.cache import SQLiteCache
2424
import langchain
25+
from datetime import datetime
2526

2627
CACHE_PATH = Path.home() / ".paperqa" / "llm_cache.db"
2728
os.makedirs(os.path.dirname(CACHE_PATH), exist_ok=True)
@@ -115,7 +116,8 @@ def add(
115116
texts, _ = read_doc(path, "", "", chunk_chars=chunk_chars)
116117
with get_openai_callback() as cb:
117118
citation = self.cite_chain.run(texts[0])
118-
print(f"Guessed citation {citation} for {cb.total_tokens} tokens")
119+
if len(citation) < 3 or "Unknown" in citation or "insufficient" in citation:
120+
citation = f"Unknown, {os.path.basename(path)}, {datetime.now().year}"
119121

120122
if path in self.docs:
121123
raise ValueError(f"Document {path} already in collection.")

paperqa/qaprompts.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@
33

44
summary_prompt = prompts.PromptTemplate(
55
input_variables=["question", "context_str"],
6-
template="Summarize the text below to help answer a question. "
7-
"Do not directly answer the question, instead provide a summary with the context of the question. "
6+
template="Summarize and provide direct quotes from the text below to help answer a question. "
7+
"Do not directly answer the question, instead provide a summary and quotes with the context of the question. "
88
"Do not use outside sources. "
99
'Reply with "Not applicable" if the text is unrelated to the question. '
10-
"Use 75 or less words. Include quotations if possible."
10+
"Use 75 or less words."
1111
"\n\n"
1212
"{context_str}\n"
1313
"\n"
@@ -18,13 +18,13 @@
1818

1919
qa_prompt = prompts.PromptTemplate(
2020
input_variables=["question", "context_str", "length"],
21-
template="Write a comprehensive answer ({length}) "
21+
template="Write an answer ({length}) "
2222
"for the question below solely based on the provided context. "
2323
"If the context is irrelevant, "
2424
'reply "I cannot answer". '
2525
"For each sentence in your answer, indicate which sources most support it "
2626
"via valid citation markers at the end of sentences, like (Example2012). "
27-
"Answer in an unbiased, balanced, and scientific tone. "
27+
"Answer in an unbiased and scholarly tone. Make clear what is your opinion. "
2828
"Use Markdown for formatting code or text, and try to use direct quotes to support arguments.\n\n"
2929
"{context_str}\n"
3030
"Question: {question}\n"

0 commit comments

Comments
 (0)