Skip to content

Commit 5f89b69

Browse files
Obinna/s3 en 1111 fix dspy error (#528)
* update dspy instrumentation and examples * bump version --------- Co-authored-by: Obinna Okafor <[email protected]>
1 parent 6be30ae commit 5f89b69

File tree

11 files changed

+18
-23
lines changed

11 files changed

+18
-23
lines changed

src/examples/dspy_example/QA_basic.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@
88

99
# configure the language model to be used by dspy
1010

11-
llm = dspy.Claude()
12-
dspy.settings.configure(lm=llm)
11+
lm = dspy.LM('claude-3-opus-20240229')
12+
dspy.configure(lm=lm)
1313

1414
# create a prompt format that says that the llm will take a question and give back an answer
1515
predict = dspy.Predict("question -> answer")

src/examples/dspy_example/QA_basic_with_chain_of_thought.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77
langtrace.init(disable_instrumentations={"all_except": ["dspy", "anthropic"]})
88

99
# configure the language model to be used by dspy
10-
llm = dspy.Claude()
11-
dspy.settings.configure(lm=llm)
10+
lm = dspy.LM('claude-3-opus-20240229')
11+
dspy.configure(lm=lm)
1212

1313

1414
# create a signature for basic question answering

src/examples/dspy_example/QA_basic_with_signature.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77
langtrace.init(disable_instrumentations={"all_except": ["dspy", "anthropic"]})
88

99
# configure the language model to be used by dspy
10-
llm = dspy.Claude()
11-
dspy.settings.configure(lm=llm)
10+
lm = dspy.LM('claude-3-opus-20240229')
11+
dspy.configure(lm=lm)
1212

1313

1414
# create a signature for basic question answering

src/examples/dspy_example/QA_multi_step_with_chain_of_thought.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77
langtrace.init(disable_instrumentations={"all_except": ["dspy", "anthropic"]})
88

99
# configure the language model to be used by dspy
10-
llm = dspy.Claude()
11-
dspy.settings.configure(lm=llm)
10+
lm = dspy.LM('claude-3-opus-20240229')
11+
dspy.configure(lm=lm)
1212

1313

1414
# create a signature for basic question answering

src/examples/dspy_example/math_problems_cot.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77

88
langtrace.init()
99

10-
turbo = dspy.OpenAI(model="gpt-3.5-turbo", max_tokens=250)
11-
dspy.settings.configure(lm=turbo)
10+
lm = dspy.LM('gpt-3.5-turbo')
11+
dspy.configure(lm=lm)
1212

1313
# Load math questions from the GSM8K dataset
1414
gsm8k = GSM8K()

src/examples/dspy_example/math_problems_cot_parallel.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@
99

1010
langtrace.init()
1111

12-
turbo = dspy.OpenAI(model="gpt-3.5-turbo", max_tokens=250)
13-
dspy.settings.configure(lm=turbo)
12+
lm = dspy.LM('gpt-3.5-turbo')
13+
dspy.configure(lm=lm)
1414

1515
# Load math questions from the GSM8K dataset
1616
gsm8k = GSM8K()

src/examples/dspy_example/program_of_thought_basic.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55

66
langtrace.init()
77

8-
turbo = dspy.OpenAI(model="gpt-3.5-turbo", max_tokens=250)
9-
dspy.settings.configure(lm=turbo)
8+
lm = dspy.LM('gpt-3.5-turbo')
9+
dspy.configure(lm=lm)
1010

1111

1212
# Define a simple signature for basic question answering

src/examples/dspy_example/react.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@
1515

1616
langtrace.init()
1717

18-
turbo = dspy.OpenAI(model="gpt-3.5-turbo", max_tokens=250)
19-
dspy.settings.configure(lm=turbo)
18+
lm = dspy.LM('gpt-3.5-turbo')
19+
dspy.configure(lm=lm)
2020

2121
colbertv2_wiki17_abstracts = dspy.ColBERTv2(
2222
url="http://20.102.90.50:2017/wiki17_abstracts"

src/langtrace_python_sdk/instrumentation/dspy/instrumentation.py

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -70,11 +70,6 @@ def _instrument(self, **kwargs):
7070
"MultiChainComparison.forward",
7171
patch_signature("MultiChainComparison.forward", version, tracer),
7272
)
73-
_W(
74-
"dspy.predict.retry",
75-
"Retry.forward",
76-
patch_signature("Retry.forward", version, tracer),
77-
)
7873
_W(
7974
"dspy.evaluate.evaluate",
8075
"Evaluate.__call__",

src/langtrace_python_sdk/instrumentation/dspy/patch.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ def traced_method(wrapped, instance, args, kwargs):
3838
prog = {
3939
"name": args[0].prog.__class__.__name__,
4040
"signature": (
41-
str(args[0].prog.signature) if args[0].prog.signature else None
41+
str(args[0].prog.signature) if hasattr(args[0].prog, "signature") else None
4242
),
4343
}
4444
span_attributes["dspy.optimizer.module.prog"] = json.dumps(prog)

0 commit comments

Comments
 (0)