Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ dependencies = [
"pydantic>=2.0",
"litellm>=1.64.0",
"diskcache>=5.6.0",
"json-repair>=0.30.0",
"json-repair>=0.54.2",
"tenacity>=8.2.3",
"anyio",
"asyncer==0.0.8",
Expand Down
31 changes: 31 additions & 0 deletions tests/adapters/test_chat_adapter.py
Original file line number Diff line number Diff line change
Expand Up @@ -649,6 +649,37 @@ class MySignature(dspy.Signature):
assert result[0]["reasoning"] == dspy.Reasoning(content="Step-by-step thinking about the capital of France")


def test_chat_adapter_parses_float_with_underscores():
"""
This test verifies that ChatAdapter can parse float numbers with underscores.
After json-repair version 0.54.1, floats like "123_456.789" are treated as normal float numbers.
"""

class Score(pydantic.BaseModel):
score: float

class MySignature(dspy.Signature):
question: str = dspy.InputField()
score: Score = dspy.OutputField()

adapter = dspy.ChatAdapter()

# Simulate a response with a float number containing underscores
with mock.patch("litellm.completion") as mock_completion:
mock_completion.return_value = ModelResponse(
choices=[
Choices(message=Message(content="[[ ## score ## ]]\n{'score': 123_456.789}\n[[ ## completed ## ]]"))
],
model="openai/gpt-4o-mini",
)

lm = dspy.LM("openai/gpt-4o-mini", cache=False)
result = adapter(lm, {}, MySignature, [], {"question": "What is the score?"})

# The underscore-separated float should be parsed as a normal float
assert result[0]["score"].score == 123456.789


def test_format_system_message():
class MySignature(dspy.Signature):
"""Answer the question with multiple answers and scores"""
Expand Down
8 changes: 4 additions & 4 deletions uv.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.