From e62decac21a1e90d8ce93ba396abe61e3b3409d2 Mon Sep 17 00:00:00 2001 From: binary-husky Date: Tue, 19 Nov 2024 15:49:29 +0000 Subject: [PATCH] change some open fn encoding to utf-8 --- crazy_functions/Latex_Function.py | 2 +- request_llms/bridge_llama2.py | 2 +- request_llms/bridge_moonshot.py | 2 +- themes/common.py | 4 ++-- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/crazy_functions/Latex_Function.py b/crazy_functions/Latex_Function.py index 51b03283e2..310aaa4b7e 100644 --- a/crazy_functions/Latex_Function.py +++ b/crazy_functions/Latex_Function.py @@ -559,7 +559,7 @@ def PDF翻译中文并重新编译PDF(txt, llm_kwargs, plugin_kwargs, chatbot, h project_folder = move_project(project_folder) # <-------------- set a hash tag for repeat-checking -------------> - with open(pj(project_folder, hash_tag + '.tag'), 'w') as f: + with open(pj(project_folder, hash_tag + '.tag'), 'w', encoding='utf8') as f: f.write(hash_tag) f.close() diff --git a/request_llms/bridge_llama2.py b/request_llms/bridge_llama2.py index ba92b21c9d..95a8cf48f6 100644 --- a/request_llms/bridge_llama2.py +++ b/request_llms/bridge_llama2.py @@ -26,7 +26,7 @@ def load_model_and_tokenizer(self): import platform huggingface_token, device = get_conf('HUGGINGFACE_ACCESS_TOKEN', 'LOCAL_MODEL_DEVICE') assert len(huggingface_token) != 0, "没有填写 HUGGINGFACE_ACCESS_TOKEN" - with open(os.path.expanduser('~/.cache/huggingface/token'), 'w') as f: + with open(os.path.expanduser('~/.cache/huggingface/token'), 'w', encoding='utf8') as f: f.write(huggingface_token) model_id = 'meta-llama/Llama-2-7b-chat-hf' with ProxyNetworkActivate('Download_LLM'): diff --git a/request_llms/bridge_moonshot.py b/request_llms/bridge_moonshot.py index e1b3cd4842..20983fd9f8 100644 --- a/request_llms/bridge_moonshot.py +++ b/request_llms/bridge_moonshot.py @@ -31,7 +31,7 @@ def __converter_file(self, user_input: str): files.append(f) for file in files: if file.split('.')[-1] in ['pdf']: - with open(file, 'r') as fp: + with open(file, 'r', encoding='utf8') as fp: from crazy_functions.crazy_utils import read_and_clean_pdf_text file_content, _ = read_and_clean_pdf_text(fp) what_ask.append({"role": "system", "content": file_content}) diff --git a/themes/common.py b/themes/common.py index dc9b0575b9..f3ee23d727 100644 --- a/themes/common.py +++ b/themes/common.py @@ -29,7 +29,7 @@ def minimize_js(common_js_path): os.remove(old_min_js) # use rjsmin to minimize `common_js_path` c_jsmin = rjsmin.jsmin - with open(common_js_path, "r") as f: + with open(common_js_path, "r", encoding='utf-8') as f: js_content = f.read() if common_js_path == "themes/common.js": js_content = inject_mutex_button_code(js_content) @@ -38,7 +38,7 @@ def minimize_js(common_js_path): sha_hash = hashlib.sha256(minimized_js_content.encode()).hexdigest()[:8] minimized_js_path = common_js_path + '.min.' + sha_hash + '.js' # save to minimized js file - with open(minimized_js_path, "w") as f: + with open(minimized_js_path, "w", encoding='utf-8') as f: f.write(minimized_js_content) # return minimized js file path return minimized_js_path