forked from AgentTorch/AgentTorch
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdspy_modules.py
More file actions
65 lines (51 loc) · 2.79 KB
/
dspy_modules.py
File metadata and controls
65 lines (51 loc) · 2.79 KB
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
import dspy
class BasicQAWillToWork(dspy.Signature):
"""
You are an individual living during the COVID-19 pandemic. You need to decide your willingness to work each month and portion of your assests you are willing to spend to meet your consumption demands, based on the current situation of NYC.
"""
history = dspy.InputField(
desc="may contain your decision in the previous months", format=list
)
question = dspy.InputField(
desc="will contain the number of COVID cases in NYC, your age and other information about the economy and your identity, to help you decide your willingness to work and consumption demands"
)
answer = dspy.OutputField(
desc="will contain single float value, between 0 and 1, representing realistic probability of your willingness to work. No other information should be there."
)
class BasicQACovid(dspy.Signature):
"""Consider a random person with the following attributes:
* age: {age}
* location: {location}
There is a novel disease. It spreads through contact. It is more dangerous to older people.
People have the option to isolate at home or continue their usual recreational activities outside.
Given this scenario, you must estimate the person's actions based on
1) the information you are given,
2) what you know about the general population with these attributes.
"There isn't enough information" and "It is unclear" are not acceptable answers.
Give a "Yes" or "No" answer, followed by a period. Give one sentence explaining your choice.
"""
history = dspy.InputField(
desc="may contain your decision in the previous months", format=list
)
question = dspy.InputField(
desc="will contain the number of weeks since a disease started (if specified), the number of new cases this week, the percentage change from the past month's average, and asks if the person chooses to isolate at home. It may have other information also."
)
answer = dspy.OutputField(
desc="Give a 'Yes' or 'No' answer, followed by a period. No other information should be there in the answer"
)
class Reflect(dspy.Signature):
"""
You are an Economic Analyst.
"""
history = dspy.InputField(desc="may contain data on previous months", format=list)
question = dspy.InputField(desc="may contain the question you are being asked")
answer = dspy.OutputField(
desc="may contain your analysis of the question asked based on the data in the history"
)
class COT(dspy.Module):
def __init__(self, qa):
super().__init__()
self.generate_answer = dspy.ChainOfThought(qa)
def forward(self, question, history):
prediction = self.generate_answer(question=question, history=history)
return dspy.Prediction(answer=prediction)