-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathpatchers.py
More file actions
43 lines (29 loc) · 1.17 KB
/
patchers.py
File metadata and controls
43 lines (29 loc) · 1.17 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
"""DSPy patchers — one patcher per coherent patch target."""
from braintrust.integrations.base import FunctionWrapperPatcher
from .tracing import _configure_wrapper
class DSPyConfigurePatcher(FunctionWrapperPatcher):
"""Patch ``dspy.configure`` to auto-add ``BraintrustDSpyCallback``."""
name = "dspy.configure"
target_path = "configure"
wrapper = _configure_wrapper
# ---------------------------------------------------------------------------
# Public helper
# ---------------------------------------------------------------------------
def patch_dspy() -> bool:
"""
Patch DSPy to automatically add Braintrust tracing callback.
After calling this, all calls to dspy.configure() will automatically
include the BraintrustDSpyCallback.
Returns:
True if DSPy was patched (or already patched), False if DSPy is not installed.
Example:
```python
import braintrust
braintrust.patch_dspy()
import dspy
lm = dspy.LM("openai/gpt-4o-mini")
dspy.configure(lm=lm) # BraintrustDSpyCallback auto-added!
```
"""
from .integration import DSPyIntegration
return DSPyIntegration.setup()