feat: add multilingual prompt template support (closes #85)#220
feat: add multilingual prompt template support (closes #85)#220Jah-yee wants to merge 2 commits intoHKUDS:mainfrom
Conversation
Made-with: Cursor
|
I did a Codex-assisted review of this PR and found a few issues worth addressing before merge:
|
… language switches atomic Made-with: Cursor
|
Thanks a lot for the Codex-assisted review on the multilingual prompts PR.
If you’d like prompt_language to default to None (opt-in only) or prefer a different env var name, I’m happy to tweak it. |
Summary
This PR adds first-class support for multilingual prompt templates, including a complete Chinese (
zh) set and a small runtime manager for switching prompt languages with lazy loading and safe fallback to English.Motivation
Right now, all prompt templates are hard-coded in English, which can reduce RAG quality and user experience for non-English users (#85). Different languages often need different phrasing for instructions and system messages to work well with LLMs. Multilingual prompts and a simple runtime selector help RAG-Anything better serve a global user base.
Changes
raganything/prompts_zh.pyraganything/prompt_manager.pyset_prompt_language(lang)to switch the active prompt language at runtime (e.g."zh","en").reset_prompts()to restore the default language and state.register_prompt_language(lang, prompts)to register additional languages (e.g."ja") without changing core code.tests/test_prompt_language.pyreset_prompts().Testing
pytestlocally includingtests/test_prompt_language.py; all tests passed."en"and"zh"to confirm correct localized templates and English fallback where needed.Thanks for your work on RAG-Anything—if you’d like different language codes, file naming, or prompt phrasing, I’m happy to revise this PR.