From 618cf5241e7b5c71ff1e34cf8c82d195a8f8a025 Mon Sep 17 00:00:00 2001 From: EricFan <45393699+flyspirit99@users.noreply.github.com> Date: Thu, 10 Aug 2023 08:54:21 +0800 Subject: [PATCH] Open file in UTF-8 encoding (#6919) (#8943) FileCallbackHandler cannot handle some language, for example: Chinese. Open file using UTF-8 encoding can fix it. @agola11 **Issue**: #6919 **Dependencies**: NO dependencies, --------- Co-authored-by: Bagatur --- libs/langchain/langchain/callbacks/file.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libs/langchain/langchain/callbacks/file.py b/libs/langchain/langchain/callbacks/file.py index 3265fa0060..d5dff48900 100644 --- a/libs/langchain/langchain/callbacks/file.py +++ b/libs/langchain/langchain/callbacks/file.py @@ -13,7 +13,7 @@ class FileCallbackHandler(BaseCallbackHandler): self, filename: str, mode: str = "a", color: Optional[str] = None ) -> None: """Initialize callback handler.""" - self.file = cast(TextIO, open(filename, mode)) + self.file = cast(TextIO, open(filename, mode, encoding="utf-8")) self.color = color def __del__(self) -> None: