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 "