Skip to content

Commit

Permalink
fix(dspy): instrument dspy rather than dspy-ai (#1113)
Browse files Browse the repository at this point in the history
  • Loading branch information
axiomofjoy authored Nov 12, 2024
1 parent a0e6f30 commit 5f6e149
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 8 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
dspy-ai >= 2.1.0
dspy >= 2.5.0
opentelemetry-sdk
opentelemetry-exporter-otlp
openinference-instrumentation-dspy
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,10 @@ dependencies = [

[project.optional-dependencies]
instruments = [
"dspy-ai >= 2.5.0",
"dspy >= 2.5.0",
]
test = [
"dspy-ai==2.5.0",
"dspy>=2.5.27",
"google-generativeai",
"opentelemetry-sdk",
"pytest-recording",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
_instruments = ("dspy-ai >= 2.1.0",)
_instruments = ("dspy >= 2.5.0",)
_supports_metrics = False
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
backtrack_handler,
)
from dspy.teleprompt import BootstrapFewShotWithRandomSearch
from litellm import AuthenticationError # type: ignore[attr-defined]
from opentelemetry import trace as trace_api
from opentelemetry.sdk import trace as trace_sdk
from opentelemetry.sdk.resources import Resource
Expand Down Expand Up @@ -291,7 +290,7 @@ def test_exception_event_recorded_on_lm_error(
) -> None:
lm = dspy.LM("openai/gpt-4", cache=False)
prompt = "Who won the World Cup in 2018?"
with pytest.raises(AuthenticationError):
with pytest.raises(Exception):
lm(prompt)
spans = in_memory_span_exporter.get_finished_spans()
assert len(spans) == 1
Expand All @@ -302,9 +301,10 @@ def test_exception_event_recorded_on_lm_error(
event = span.events[0]
assert event.name == "exception"
assert (event_attributes := event.attributes) is not None
assert event_attributes["exception.type"] == "litellm.exceptions.AuthenticationError"
assert isinstance(exception_type := event_attributes["exception.type"], str)
assert exception_type.startswith("litellm.exceptions")
assert isinstance(exception_message := event_attributes["exception.message"], str)
assert "401" in exception_message
assert "Connection error" in exception_message or "401" in exception_message
attributes = dict(span.attributes or {})
assert attributes.pop(OPENINFERENCE_SPAN_KIND) == LLM
assert attributes.pop(INPUT_MIME_TYPE) == JSON
Expand Down

0 comments on commit 5f6e149

Please sign in to comment.