-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdspy_module_examples.py
More file actions
46 lines (37 loc) · 1.25 KB
/
dspy_module_examples.py
File metadata and controls
46 lines (37 loc) · 1.25 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
# from the notebook page
# What DSPy Modules are currently built-in?
# dspy.Predict:
# dspy.ChainOfThought:
# dspy.ProgramOfThought:
# dspy.ReAct:
# dspy.MultiChainComparison:
# We also have some function-style modules:
# dspy.majority:
### all modules use Predict internally <-- ********
import dspy
lm = dspy.OpenAI(
model='gpt-3.5-turbo-1106',
max_tokens=300,
)
dspy.configure(lm=lm)
sentence = "it's a charming and often affecting journey."
# RMB: chgd sentence to comment and sentiment to feelings for demo
classify = dspy.Predict('comment -> feelings')
response = classify(sentence=sentence)
print("PREDICT")
print(response.feelings) # and so have to use feelings here also
print(f"\n{'-'*50}\n")
question = "What's something great about the ColBERT retrieval model?"
classify = dspy.ChainOfThought('question -> answer', n=5)
response = classify(question=question)
print("CoT")
print(response.answer)
print("\nRATIONALE for CoT answer")
print(response.rationale)
print(f"\n{'-'*50}\n")
question = "What's something great about the ColBERT retrieval model?"
classify = dspy.ReAct('question -> answer')
response = classify(question=question)
print("ReAct")
print(response.answer)
print(f"\n{'-'*50}\n")