From c7d66ee9bd22672bc7bdf23dadb9428f71e8e0ad Mon Sep 17 00:00:00 2001 From: Amirreza <20891968+ItzAmirreza@users.noreply.github.com> Date: Sat, 24 May 2025 21:37:42 +0200 Subject: [PATCH] Fixes utf-8 formatting issues in optimization saves --- dspy/primitives/module.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/dspy/primitives/module.py b/dspy/primitives/module.py index 3ddaf74d66..16ae172bb0 100644 --- a/dspy/primitives/module.py +++ b/dspy/primitives/module.py @@ -205,8 +205,8 @@ def save(self, path, save_program=False): f"Saving failed with error: {e}. Please remove the non-picklable attributes from your DSPy program, " "or consider using state-only saving by setting `save_program=False`." ) - with open(path / "metadata.json", "w") as f: - ujson.dump(metadata, f, indent=2) + with open(path / "metadata.json", "w", encoding="utf-8") as f: + ujson.dump(metadata, f, indent=2, ensure_ascii=False) return @@ -214,8 +214,8 @@ def save(self, path, save_program=False): state["metadata"] = metadata if path.suffix == ".json": try: - with open(path, "w") as f: - f.write(ujson.dumps(state, indent=2)) + with open(path, "w", encoding="utf-8") as f: + f.write(ujson.dumps(state, indent=2 , ensure_ascii=False)) except Exception as e: raise RuntimeError( f"Failed to save state to {path} with error: {e}. Your DSPy program may contain non "