Skip to content

Commit 6afb505

Browse files
authored
Change save and load encode to utf-8 (#1836)
After adapting files to Portuguese and saving. When recovering, exceptions like these are common due to Portuguese symbols. Fixing by changing to utf-8 standard save (c:\Users\jmess\miniconda3\envs\rag\Lib\site-packages\ragas\prompt\pydantic_prompt.py:333) save_prompts (c:\Users\jmess\miniconda3\envs\rag\Lib\site-packages\ragas\prompt\mixin.py:97) <module> (d:\GitHub\rag_eval\Untitled-1.py:82) _run_code (c:\Users\jmess\miniconda3\envs\rag\Lib\runpy.py:88) _run_module_as_main (Current frame) (c:\Users\jmess\miniconda3\envs\rag\Lib\runpy.py:198) [Chained Exc: 'charmap' codec can't decode byte 0x81 in position 470: character maps to <undefined>] <module> (d:\GitHub\rag_eval\Untitled-1.py:77) [Chained Exc: 'charmap' codec can't decode byte 0x81 in position 470: character maps to <undefined>] load_prompts (c:\Users\jmess\miniconda3\envs\rag\Lib\site-packages\ragas\prompt\mixin.py:119) [Chained Exc: 'charmap' codec can't decode byte 0x81 in position 470: character maps to <undefined>] load (c:\Users\jmess\miniconda3\envs\rag\Lib\site-packages\ragas\prompt\pydantic_prompt.py:341) [Chained Exc: 'charmap' codec can't decode byte 0x81 in position 470: character maps to <undefined>] load (c:\Users\jmess\miniconda3\envs\rag\Lib\json\__init__.py:293) [Chained Exc: 'charmap' codec can't decode byte 0x81 in position 470: character maps to <undefined>] decode (c:\Users\jmess\miniconda3\envs\rag\Lib\encodings\cp1252.py:23)
1 parent 36564a4 commit 6afb505

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

src/ragas/prompt/pydantic_prompt.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -328,13 +328,13 @@ def save(self, file_path: str):
328328
}
329329
if os.path.exists(file_path):
330330
raise FileExistsError(f"The file '{file_path}' already exists.")
331-
with open(file_path, "w") as f:
331+
with open(file_path, "w", encoding="utf-8") as f:
332332
json.dump(data, f, indent=2, ensure_ascii=False)
333333
print(f"Prompt saved to {file_path}")
334334

335335
@classmethod
336336
def load(cls, file_path: str) -> "PydanticPrompt[InputModel, OutputModel]":
337-
with open(file_path, "r") as f:
337+
with open(file_path, "r", encoding="utf-8") as f:
338338
data = json.load(f)
339339

340340
# You might want to add version compatibility checks here

0 commit comments

Comments
 (0)