From 39c960f16b9608392586835deaf69a976c638564 Mon Sep 17 00:00:00 2001 From: shizidushu Date: Tue, 18 Jun 2024 18:18:29 +0000 Subject: [PATCH] dump json as utf-8 --- llama-index-core/llama_index/core/schema.py | 2 +- .../llama_index/core/storage/chat_store/simple_chat_store.py | 2 +- .../llama_index/core/storage/kvstore/simple_kvstore.py | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/llama-index-core/llama_index/core/schema.py b/llama-index-core/llama_index/core/schema.py index 4e9c93d32ae87..28097c91f7401 100644 --- a/llama-index-core/llama_index/core/schema.py +++ b/llama-index-core/llama_index/core/schema.py @@ -100,7 +100,7 @@ def to_dict(self, **kwargs: Any) -> Dict[str, Any]: def to_json(self, **kwargs: Any) -> str: data = self.to_dict(**kwargs) - return json.dumps(data) + return json.dumps(data, ensure_ascii=False, indent=4) # TODO: return type here not supported by current mypy version @classmethod diff --git a/llama-index-core/llama_index/core/storage/chat_store/simple_chat_store.py b/llama-index-core/llama_index/core/storage/chat_store/simple_chat_store.py index 47c6a3172cbe6..fbd724fed7020 100644 --- a/llama-index-core/llama_index/core/storage/chat_store/simple_chat_store.py +++ b/llama-index-core/llama_index/core/storage/chat_store/simple_chat_store.py @@ -70,7 +70,7 @@ def persist( if not fs.exists(dirpath): fs.makedirs(dirpath) - with fs.open(persist_path, "w") as f: + with fs.open(persist_path, "w", encoding="utf8") as f: f.write(json.dumps(self.json())) @classmethod diff --git a/llama-index-core/llama_index/core/storage/kvstore/simple_kvstore.py b/llama-index-core/llama_index/core/storage/kvstore/simple_kvstore.py index 98f1bde5c8a50..6b88844d731c9 100644 --- a/llama-index-core/llama_index/core/storage/kvstore/simple_kvstore.py +++ b/llama-index-core/llama_index/core/storage/kvstore/simple_kvstore.py @@ -84,8 +84,8 @@ def persist( if not fs.exists(dirpath): fs.makedirs(dirpath) - with fs.open(persist_path, "w") as f: - f.write(json.dumps(self._data)) + with fs.open(persist_path, "w", encoding="utf-8") as f: + f.write(json.dumps(self._data, ensure_ascii=False, indent=4)) @classmethod def from_persist_path(