Skip to content

Commit e2b5fe9

Browse files
authored
Fixes utf-8 formatting issues in optimization saves (#8272)
1 parent 9b2e1c6 commit e2b5fe9

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

dspy/primitives/module.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -218,17 +218,17 @@ def save(self, path, save_program=False, modules_to_serialize=None):
218218
f"Saving failed with error: {e}. Please remove the non-picklable attributes from your DSPy program, "
219219
"or consider using state-only saving by setting `save_program=False`."
220220
)
221-
with open(path / "metadata.json", "w") as f:
222-
ujson.dump(metadata, f, indent=2)
221+
with open(path / "metadata.json", "w", encoding="utf-8") as f:
222+
ujson.dump(metadata, f, indent=2, ensure_ascii=False)
223223

224224
return
225225

226226
state = self.dump_state()
227227
state["metadata"] = metadata
228228
if path.suffix == ".json":
229229
try:
230-
with open(path, "w") as f:
231-
f.write(ujson.dumps(state, indent=2))
230+
with open(path, "w", encoding="utf-8") as f:
231+
f.write(ujson.dumps(state, indent=2 , ensure_ascii=False))
232232
except Exception as e:
233233
raise RuntimeError(
234234
f"Failed to save state to {path} with error: {e}. Your DSPy program may contain non "

0 commit comments

Comments
 (0)