Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

improve system prompt; add verbose_logging; add glossary for openai; Beautify the command-line output ; Update README #874

Open
wants to merge 28 commits into
base: main
Choose a base branch
from

Conversation

popcion
Copy link
Contributor

@popcion popcion commented Mar 7, 2025

  • 系统提示词优化为三步翻译法,提升翻译性能,
  • 增加命令行中隐藏_CHAT_SAMPLE_CHAT_SYSTEM_TEMPLATE的选项verbose_logging,即使在调试模式下,每次都输出也过于冗余了,默认隐藏
  • 为openai类增加术语表,指导模型进行翻译,新增OPENAI_GLOSSARY_PATH参数,可使用sakura、galtransl、mit(与post_dict/pre_dict一样的格式)格式的术语表
  • 增加自动检测术语表功能,仅提取对当前翻译有用的术语表项目发送给模型,降低术语表行数过多时的token浪费及防止模型智力下降
  • 将字典和术语表统一到一个文件夹下,增加相关示例
  • 调整默认参数,以在默认状态下获得更好的翻译效果
  • 美化了web命令行输出,让使用openai时的命令行中的prompt和respons更清晰
    调整web模式下final输出文件夹命名的顺序,重点突出参数以便查看
    修复旧版翻译同一张图片时由于hash相同会something went wrong的遗留问题

才发现新版web模式不会保存翻译完成的图片...

[edit]

  • 更新readme

@popcion popcion changed the title improve system prompt; add verbose_logging; add glossory for openai; Beautify the command-line output improve system prompt; add verbose_logging; add glossory for openai; Beautify the command-line output ; Update README Mar 8, 2025
@SamuelWN
Copy link
Contributor

SamuelWN commented Mar 8, 2025

@popcion
Interesting idea.

I think that a lot of the additions could be worth moving to a new parent class (e.g. CommonGPTTranslator, as I have in my JSON branch). They seem like they could be useful for many online translators, not just chatgpt.py.

e.g.

common_gpt.py:

class CommonGPTTranslator(ConfigGPT, CommonTranslator):
    def __init__(self, config_key: str):
        ConfigGPT.__init__(self, config_key=config_key)
        CommonTranslator.__init__(self)
    ...
    
    def print_boxed(self, text, border_color="blue", title=f"{self.__class__.__name__} Output"):  
        ...
    
    def load_glossary(self, path):
        ...

    ...

Can probably move some other functions there, too. e.g. :

    def _cannot_assist(self, response: str) -> bool:
        ...

chatgpt.py:

class OpenAITranslator(CommonGPTTranslator):
    ...

@popcion popcion changed the title improve system prompt; add verbose_logging; add glossory for openai; Beautify the command-line output ; Update README improve system prompt; add verbose_logging; add glossary for openai; Beautify the command-line output ; Update README Mar 8, 2025
@popcion
Copy link
Contributor Author

popcion commented Mar 8, 2025

@SamuelWN
That's a great idea! If you're interested, we can assign this task to you after the PR gets merged. Personally, I think OpenAI is already versatile enough - nowadays, if you want to use translation models with excellent quality, you simply can't bypass OpenAI. It's basically compatible with all the best models out there.

Regarding glossary, this is actually an old issue. glossaries have been used to guide AI translation since the end of 2022. I've always wondered why a project with so many users doesn't have a glossary feature.

Adding a glossary is on the TODO list, and I considered adding it when implementing the replacement dictionary. However, automatically adding a glossary is a new reference point. Furthermore, taking inspiration from this project , we could even create an automated workflow that generates and adds glossaries. It would work by first performing OCR on the entire comic, then generating a specific terminology glossary for that comic based on the merged textline results, and finally proceeding with translation and subsequent processes. This approach could serve as a superior alternative to the current automatic terminology matching system.

glossory  -> glossary
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants