Skip to content

armgit / dspy

Public Imported from GitHub
0

DSPy: The framework for programming—not prompting—language models

Python

Fix Pydantic v2 deprecation warning in json_adapter (#8263)

Brian Donghee Shin63020fdd5db5
diff --git a/dspy/adapters/json_adapter.py b/dspy/adapters/json_adapter.py
index e507c66e0..e43561b0e 100644
--- a/dspy/adapters/json_adapter.py
+++ b/dspy/adapters/json_adapter.py
@@ -219,8 +219,8 @@ def _get_structured_outputs_response_format(signature: SignatureMeta) -> type[py
# Build the model with extra fields forbidden.
pydantic_model = pydantic.create_model(
"DSPyProgramOutputs",
+ __config__=pydantic.ConfigDict(extra="forbid"),
**fields,
- __config__=type("Config", (), {"extra": "forbid"}),
)
# Generate the initial schema.
diff --git a/tests/adapters/test_json_adapter.py b/tests/adapters/test_json_adapter.py
index f1449e4ef..cd561fe04 100644
--- a/tests/adapters/test_json_adapter.py
+++ b/tests/adapters/test_json_adapter.py
@@ -58,7 +58,7 @@ def test_json_adapter_falls_back_when_structured_outputs_fails():
input1: str = dspy.InputField()
output1: str = dspy.OutputField(desc="String output field")
- dspy.configure(lm=dspy.LM(model="openai/gpt4o"), adapter=dspy.JSONAdapter())
+ dspy.configure(lm=dspy.LM(model="openai/gpt4o", cache=False), adapter=dspy.JSONAdapter())
program = dspy.Predict(TestSignature)
with mock.patch("litellm.completion") as mock_completion:
mock_completion.side_effect = [Exception("Bad structured outputs!"), mock_completion.return_value]