The SaveLangchain function in PrintUtils.py writes MarkdownVersion to a file. The default encoding for file writing on Windows is cp1252, which doesn't support many Unicode characters and will sometimes cause a crash.
All lines that open files need to be specified as utf-8 like this:
with open(ThisLogPathJSON, "w", encoding="utf-8") as f:
with open(ThisLogPathMD, "w", encoding="utf-8") as f:
with open(f"{self.LogDirPrefix}/Story.md", "w", encoding="utf-8") as f:
|
with open(ThisLogPathJSON, "w") as f: |
|
f.write(json.dumps(_LangChain, indent=4, sort_keys=True)) |
|
|
|
# Now, Save Markdown Version |
|
with open(ThisLogPathMD, "w") as f: |
|
MarkdownVersion:str = f"# Debug LangChain {LangChainDebugTitle}\n**Note: '```' tags have been removed in this version.**\n" |
|
for Message in _LangChain: |
|
MarkdownVersion += f"\n\n\n# Role: {Message['role']}\n" |
|
MarkdownVersion += f"```{Message['content'].replace('```', '')}```" |
|
f.write(MarkdownVersion) |
|
|
|
self.Log(f"Wrote This Language Chain ({LangChainDebugTitle}) To Debug File {ThisLogPathMD}", 5) |
|
|
|
|
|
# Saves the given story to disk |
|
def SaveStory(self, _StoryContent:str): |
|
|
|
with open(f"{self.LogDirPrefix}/Story.md", "w") as f: |
The SaveLangchain function in PrintUtils.py writes MarkdownVersion to a file. The default encoding for file writing on Windows is cp1252, which doesn't support many Unicode characters and will sometimes cause a crash.
All lines that open files need to be specified as utf-8 like this:
with open(ThisLogPathJSON, "w", encoding="utf-8") as f:with open(ThisLogPathMD, "w", encoding="utf-8") as f:with open(f"{self.LogDirPrefix}/Story.md", "w", encoding="utf-8") as f:AIStoryWriter/Writer/PrintUtils.py
Lines 41 to 58 in 25d6753