Skip to content
Open
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
7 changes: 6 additions & 1 deletion dspy/clients/lm.py
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,12 @@ def dump_state(self):
"launch_kwargs",
"train_kwargs",
]
return {key: getattr(self, key) for key in state_keys} | self.kwargs

kwargs = self.kwargs
if "max_completion_tokens" in kwargs:
kwargs["max_tokens"] = kwargs.pop("max_completion_tokens")

return {key: getattr(self, key) for key in state_keys} | kwargs

def _check_truncation(self, results):
if self.model_type != "responses" and any(c.finish_reason == "length" for c in results["choices"]):
Expand Down
24 changes: 24 additions & 0 deletions tests/clients/test_lm.py
Original file line number Diff line number Diff line change
Expand Up @@ -326,6 +326,30 @@ def test_dump_state():
}


def test_dump_state_with_reasoning_model():
lm = dspy.LM(
model="openai/gpt-5",
model_type="chat",
temperature=1,
max_tokens=32000,
num_retries=10,
launch_kwargs={"temperature": 1},
train_kwargs={"temperature": 5},
)

assert lm.dump_state() == {
"model": "openai/gpt-5",
"model_type": "chat",
"temperature": 1,
"max_tokens": 32000,
"num_retries": 10,
"cache": True,
"finetuning_model": None,
"launch_kwargs": {"temperature": 1},
"train_kwargs": {"temperature": 5},
}


def test_exponential_backoff_retry():
time_counter = []

Expand Down