Skip to content

Commit 76cdf9e

Browse files
committed
style
1 parent a44edd0 commit 76cdf9e

File tree

3 files changed

+25
-18
lines changed

3 files changed

+25
-18
lines changed

parea/client.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ def trace_dspy(self):
113113
try:
114114
import openai
115115

116-
if openai.version.__version__.startswith('0.'):
116+
if openai.version.__version__.startswith("0."):
117117
self.wrap_openai_client(openai, "dspy")
118118
else:
119119
self.auto_trace_openai_clients("dspy")

parea/cookbook/dspy/dspy_examples.py

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -21,25 +21,27 @@
2121
dspy.settings.configure(rm=colbertv2_wiki17_abstracts)
2222

2323

24-
#Define a simple signature for basic question answering
24+
# Define a simple signature for basic question answering
2525
class BasicQA(dspy.Signature):
2626
"""Answer questions with short factoid answers."""
27+
2728
question = dspy.InputField()
2829
answer = dspy.OutputField(desc="often between 1 and 5 words")
2930

31+
3032
# Pass signature to Predict module
3133
generate_answer = dspy.Predict(BasicQA)
3234

3335
# Call the predictor on a particular input.
34-
question='What is the color of the sky?'
36+
question = "What is the color of the sky?"
3537
pred = generate_answer(question=question)
3638

3739
print(f"Question: {question}")
3840
print(f"Predicted Answer: {pred.answer}")
3941
question = "What's something great about the ColBERT retrieval model ?!?abc"
4042

4143
# 1) Declare with a signature, and pass some config.
42-
classify = dspy.ChainOfThought('question -> answer', n=1)
44+
classify = dspy.ChainOfThought("question -> answer", n=1)
4345

4446
# 2) Call with input argument.
4547
response = classify(question=question)
@@ -51,14 +53,16 @@ class BasicQA(dspy.Signature):
5153
# Define a simple signature for basic question answering
5254
class BasicQA(dspy.Signature):
5355
"""Answer questions with short factoid answers."""
56+
5457
question = dspy.InputField()
5558
answer = dspy.OutputField(desc="often between 1 and 5 words")
5659

57-
#Pass signature to ChainOfThought module
60+
61+
# Pass signature to ChainOfThought module
5862
generate_answer = dspy.ChainOfThought(BasicQA)
5963

6064
# Call the predictor on a particular input.
61-
question='What is the color of the sky?12'
65+
question = "What is the color of the sky?12"
6266
pred = generate_answer(question=question)
6367

6468
print(f"Question: {question}")
@@ -67,9 +71,11 @@ class BasicQA(dspy.Signature):
6771

6872
class BasicQA(dspy.Signature):
6973
"""Answer questions with short factoid answers."""
74+
7075
question = dspy.InputField()
7176
answer = dspy.OutputField(desc="often between 1 and 5 words")
7277

78+
7379
# Example completions generated by a model for reference
7480
completions = [
7581
dspy.Prediction(rationale=" I recall that during clear days, the sky often appears this colo12r", answer="blue"),
@@ -81,25 +87,27 @@ class BasicQA(dspy.Signature):
8187
compare_answers = dspy.MultiChainComparison(BasicQA)
8288

8389
# Call the MultiChainComparison on the completions
84-
question = ' What is the color of th e sky14?'
90+
question = " What is the color of th e sky14?"
8591
final_pred = compare_answers(completions, question=question)
8692

8793
print(f"Question: {question}")
8894
print(f"Final Predicted Answer (after comparison): {final_pred.answer}")
8995
print(f"Final Rationale: {final_pred.rationale}")
9096

9197

92-
#Define a simple signature for basic question answering
98+
# Define a simple signature for basic question answering
9399
class GenerateAnswer(dspy.Signature):
94100
"""Answer questions with short factoid answers."""
101+
95102
question = dspy.InputField()
96103
answer = dspy.OutputField(desc="often between 1 and 5 words")
97104

105+
98106
# Pass signature to ProgramOfThought Module
99107
pot = dspy.ProgramOfThought(GenerateAnswer)
100108

101-
#Call the ProgramOfThought module on a particular input
102-
question = 'Sarah has 5 applez. She buys 123 more apples from the store. How many apples does Sarah have now?'
109+
# Call the ProgramOfThought module on a particular input
110+
question = "Sarah has 5 applez. She buys 123 more apples from the store. How many apples does Sarah have now?"
103111
result = pot(question=question)
104112

105113
print(f"Question: {question}")
@@ -125,14 +133,14 @@ class BasicQA(dspy.Signature):
125133
print(f"Final Predicted Answer (after ReAct process): {result.answer}")
126134

127135

128-
query='Where was the first FIFA World Cup held?12'
136+
query = "Where was the first FIFA World Cup held?12"
129137

130138

131139
# Call the retriever on a particular query.
132140
retrieve = dspy.Retrieve(k=3)
133141
topK_passages = retrieve(query).passages
134142

135-
print(f"Top {retrieve.k} passages for question: {query} \n", '-' * 30, '\n')
143+
print(f"Top {retrieve.k} passages for question: {query} \n", "-" * 30, "\n")
136144

137145
for idx, passage in enumerate(topK_passages):
138-
print(f'{idx+1}]', passage, '\n')
146+
print(f"{idx+1}]", passage, "\n")

parea/utils/trace_integrations/dspy.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ def instrument(self) -> None:
2323
module=_DSP_MODULE_NAME,
2424
name=lm.__name__ + ".basic_request",
2525
factory=CopyableFunctionWrapper,
26-
args=(_GeneralDSPyWrapper('request'),),
26+
args=(_GeneralDSPyWrapper("request"),),
2727
)
2828

2929
# Predict is a concrete (non-abstract) class that may be invoked
@@ -46,12 +46,11 @@ def instrument(self) -> None:
4646
args=(_PredictForwardWrapper(),),
4747
)
4848

49-
5049
wrap_object(
5150
module=_DSPY_MODULE_NAME,
5251
name="Retrieve.forward",
5352
factory=CopyableFunctionWrapper,
54-
args=(_GeneralDSPyWrapper('forward'),),
53+
args=(_GeneralDSPyWrapper("forward"),),
5554
)
5655

5756
wrap_object(
@@ -61,7 +60,7 @@ def instrument(self) -> None:
6160
# forward method and invokes that method using __call__.
6261
name="Module.__call__",
6362
factory=CopyableFunctionWrapper,
64-
args=(_GeneralDSPyWrapper('forward'),),
63+
args=(_GeneralDSPyWrapper("forward"),),
6564
)
6665

6766
# At this time, there is no common parent class for retriever models as
@@ -71,7 +70,7 @@ def instrument(self) -> None:
7170
module=_DSP_MODULE_NAME,
7271
name="ColBERTv2.__call__",
7372
factory=CopyableFunctionWrapper,
74-
args=(_GeneralDSPyWrapper('__call__'),),
73+
args=(_GeneralDSPyWrapper("__call__"),),
7574
)
7675

7776

0 commit comments

Comments
 (0)