-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathqa.py
48 lines (33 loc) · 1.44 KB
/
qa.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
from fvalues import F
from ice.recipe import recipe
DEFAULT_CONTEXT = "We're running a hackathon on 9/9/2022 to decompose complex reasoning tasks into subtasks that are easier to automate & evaluate with language models. Our team is currently breaking down reasoning about the quality of evidence in randomized controlled trials into smaller tasks e.g. placebo, intervention adherence rate, blinding procedure, etc."
DEFAULT_QUESTION = "What is happening on 9/9/2022?"
def make_qa_prompt(context: str, question: str) -> str:
return F(
f"""
Background text: "{context}"
Answer the following question about the background text above:
Question: "{question}"
Answer: "Let's think step by step.
"""
).strip()
def make_improvement_prompt(context: str, answer: str, question: str) -> str:
return F(
f"""
Background text: "{context}"
Question: "{question}"
Here is an answer to the above question and above background text.
Answer: "{answer}"
How would we improve the answer?
Relevant questions: "
"""
).strip()
async def answer(
context: str = DEFAULT_CONTEXT, question: str = DEFAULT_QUESTION
) -> str:
prompt = make_qa_prompt(context, question)
answer = await recipe.agent().complete(prompt=prompt, stop='"')
improvement_prompt = make_improvement_prompt(context, answer, question)
improved_answer = await recipe.agent().complete(prompt=improvement_prompt, stop='"')
return improved_answer
recipe.main(answer)