Skip to content

Commit fc43cae

Browse files
Upgrade json_repair to fix parsing issue of underscore-style float number (#9088)
* Upgrade json_repair to fix parsing issue * fix tests
1 parent 02b148e commit fc43cae

File tree

3 files changed

+36
-5
lines changed

3 files changed

+36
-5
lines changed

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ dependencies = [
3030
"pydantic>=2.0",
3131
"litellm>=1.64.0",
3232
"diskcache>=5.6.0",
33-
"json-repair>=0.30.0",
33+
"json-repair>=0.54.2",
3434
"tenacity>=8.2.3",
3535
"anyio",
3636
"asyncer==0.0.8",

tests/adapters/test_chat_adapter.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -649,6 +649,37 @@ class MySignature(dspy.Signature):
649649
assert result[0]["reasoning"] == dspy.Reasoning(content="Step-by-step thinking about the capital of France")
650650

651651

652+
def test_chat_adapter_parses_float_with_underscores():
653+
"""
654+
This test verifies that ChatAdapter can parse float numbers with underscores.
655+
After json-repair version 0.54.1, floats like "123_456.789" are treated as normal float numbers.
656+
"""
657+
658+
class Score(pydantic.BaseModel):
659+
score: float
660+
661+
class MySignature(dspy.Signature):
662+
question: str = dspy.InputField()
663+
score: Score = dspy.OutputField()
664+
665+
adapter = dspy.ChatAdapter()
666+
667+
# Simulate a response with a float number containing underscores
668+
with mock.patch("litellm.completion") as mock_completion:
669+
mock_completion.return_value = ModelResponse(
670+
choices=[
671+
Choices(message=Message(content="[[ ## score ## ]]\n{'score': 123_456.789}\n[[ ## completed ## ]]"))
672+
],
673+
model="openai/gpt-4o-mini",
674+
)
675+
676+
lm = dspy.LM("openai/gpt-4o-mini", cache=False)
677+
result = adapter(lm, {}, MySignature, [], {"question": "What is the score?"})
678+
679+
# The underscore-separated float should be parsed as a normal float
680+
assert result[0]["score"].score == 123456.789
681+
682+
652683
def test_format_system_message():
653684
class MySignature(dspy.Signature):
654685
"""Answer the question with multiple answers and scores"""

uv.lock

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)