重构 PUA 占位符映射为数据驱动,消除重复硬编码#2
Open
nodoka-ai wants to merge 1 commit intoSomiaWhiteRing:mainfrom
Open
Conversation
- 将 pre_process_text_for_llm 和 restore_pua_placeholders 中散落的 硬编码 replace 调用替换为统一的映射表 _PUA_MAPPING - 反向映射 _PUA_REVERSE_MAPPING 自动从正向映射生成,确保一致性 - 新增映射只需在 _PUA_MAPPING 中加一行,无需同时修改两个函数 - 映射顺序保持不变(长模式优先),行为完全等价
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.
改动内容
将 PUA 占位符的正向/反向映射统一为一张表
问题:
pre_process_text_for_llm和restore_pua_placeholders各自用十几行硬编码的.replace()调用来做 PUA 占位符的替换和还原。两个函数的映射关系必须严格对应,但分散在两处维护,新增映射时需要同时改两个地方,容易遗漏或顺序出错。改进:
_PUA_MAPPING列表,集中定义所有「原始标记 → PUA 字符」的映射关系_PUA_REVERSE_MAPPING自动从正向映射生成,保证一致性pre_process_text_for_llm和restore_pua_placeholders改为遍历映射表,各只需 3 行\!\n排在\!前面),行为完全等价_PUA_MAPPING中加一行影响范围
纯重构,不改变任何运行时行为。映射关系和替换顺序与原实现完全一致。