fix: 本地模型翻译时 JsonSerializer 对非 ASCII 字符的 \uXXXX 转义导致翻译失败#4
Open
aa754105233 wants to merge 1 commit into
Open
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
hey,大佬你好,我用这个工具时出现了些问题,我拷了源代码过来解析修复了,麻烦你有空查看。
原因
用本地模型翻译时(Sakura),出现了无论什么情况,翻译只返回原文的bug。
根因
System.Text.Json.JsonSerializer.Serialize() 默认会将所有非 ASCII 字符(如日文假名、汉字)
转义为 \uXXXX 格式。例如 "こんにちは" 被序列化为 "\u3053\u3093\u306B\u3061\u306F"。
这些转义序列作为用户消息发送给 LLM 后:
表现为:游戏内文本始终显示日文原文不翻译,并且存入了"原文=译文"的错误缓存,
形成死循环。
修复
4 处 JsonSerializer.Serialize() 调用增加 UnsafeRelaxedJsonEscaping 编码器,
使日文等非 ASCII 字符以原始字形发送给 LLM: