Skip to content

Commit 63020fd

Browse files
Fix Pydantic v2 deprecation warning in json_adapter (#8263)
* Fix Pydantic v2 deprecation warning in json_adapter * Fix json adapter tests * use __config__ field --------- Co-authored-by: chenmoneygithub <chen.qian@databricks.com>
1 parent 37a4626 commit 63020fd

File tree

2 files changed

+2
-2
lines changed

2 files changed

+2
-2
lines changed

dspy/adapters/json_adapter.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -219,8 +219,8 @@ def _get_structured_outputs_response_format(signature: SignatureMeta) -> type[py
219219
# Build the model with extra fields forbidden.
220220
pydantic_model = pydantic.create_model(
221221
"DSPyProgramOutputs",
222+
__config__=pydantic.ConfigDict(extra="forbid"),
222223
**fields,
223-
__config__=type("Config", (), {"extra": "forbid"}),
224224
)
225225

226226
# Generate the initial schema.

tests/adapters/test_json_adapter.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ class TestSignature(dspy.Signature):
5858
input1: str = dspy.InputField()
5959
output1: str = dspy.OutputField(desc="String output field")
6060

61-
dspy.configure(lm=dspy.LM(model="openai/gpt4o"), adapter=dspy.JSONAdapter())
61+
dspy.configure(lm=dspy.LM(model="openai/gpt4o", cache=False), adapter=dspy.JSONAdapter())
6262
program = dspy.Predict(TestSignature)
6363
with mock.patch("litellm.completion") as mock_completion:
6464
mock_completion.side_effect = [Exception("Bad structured outputs!"), mock_completion.return_value]

0 commit comments

Comments
 (0)