diff --git a/README.md b/README.md index 65adc371..6a63af8e 100644 --- a/README.md +++ b/README.md @@ -36,6 +36,7 @@ return { show_help = "yes", -- Show help text for CopilotChatInPlace, default: yes debug = false, -- Enable or disable debug mode, the log file will be in ~/.local/state/nvim/CopilotChat.nvim.log disable_extra_info = 'no', -- Disable extra information (e.g: system prompt) in the response. + language = "English" -- Copilot answer language settings when using default prompts. Default language is English. -- proxy = "socks5://127.0.0.1:3000", -- Proxies requests via https or socks. }, build = function() diff --git a/lua/CopilotChat/init.lua b/lua/CopilotChat/init.lua index e80fd184..99994646 100644 --- a/lua/CopilotChat/init.lua +++ b/lua/CopilotChat/init.lua @@ -15,6 +15,7 @@ _COPILOT_CHAT_GLOBAL_CONFIG = {} -- - disable_extra_info: ('yes' | 'no') default: 'yes'. -- - hide_system_prompt: ('yes' | 'no') default: 'yes'. -- - proxy: (string?) default: ''. +-- - language: (string?) default: ''. -- - prompts: (table?) default: default_prompts. -- - debug: (boolean?) default: false. M.setup = function(options) @@ -22,6 +23,7 @@ M.setup = function(options) vim.g.copilot_chat_disable_separators = options and options.disable_extra_info or 'yes' vim.g.copilot_chat_hide_system_prompt = options and options.hide_system_prompt or 'yes' vim.g.copilot_chat_proxy = options and options.proxy or '' + vim.g.copilot_chat_language = options and options.language or '' local debug = options and options.debug or false _COPILOT_CHAT_GLOBAL_CONFIG.debug = debug diff --git a/rplugin/python3/CopilotChat/handlers/chat_handler.py b/rplugin/python3/CopilotChat/handlers/chat_handler.py index 4d3e88fc..f643614a 100644 --- a/rplugin/python3/CopilotChat/handlers/chat_handler.py +++ b/rplugin/python3/CopilotChat/handlers/chat_handler.py @@ -26,6 +26,7 @@ def __init__(self, nvim: MyNvim, buffer: MyBuffer): self.copilot: Copilot = None self.buffer: MyBuffer = buffer self.proxy: str = os.getenv("HTTPS_PROXY") or os.getenv("ALL_PROXY") or "" + self.language = self.nvim.eval("g:copilot_chat_language") # public @@ -79,6 +80,8 @@ def _construct_system_prompt(self, prompt: str): system_prompt = system_prompts.COPILOT_TESTS elif prompt == system_prompts.EXPLAIN_SHORTCUT: system_prompt = system_prompts.COPILOT_EXPLAIN + if self.language != "": + system_prompt = system_prompt + "\n" + system_prompts.PROMPT_ANSWER_LANGUAGE_TEMPLATE.substitute(language=self.language) return system_prompt def _add_start_separator( diff --git a/rplugin/python3/CopilotChat/handlers/inplace_chat_handler.py b/rplugin/python3/CopilotChat/handlers/inplace_chat_handler.py index ed938c30..1f206527 100644 --- a/rplugin/python3/CopilotChat/handlers/inplace_chat_handler.py +++ b/rplugin/python3/CopilotChat/handlers/inplace_chat_handler.py @@ -20,6 +20,7 @@ def __init__(self, nvim: MyNvim): self.diff_mode: bool = False self.model: str = MODEL_GPT4 self.system_prompt: str = "SENIOR_DEVELOPER_PROMPT" + self.language = self.nvim.eval("g:copilot_chat_language") # Add user prompts collection self.user_prompts = self.nvim.eval("g:copilot_chat_user_prompts") diff --git a/rplugin/python3/CopilotChat/handlers/vsplit_chat_handler.py b/rplugin/python3/CopilotChat/handlers/vsplit_chat_handler.py index e959debb..16dce5cd 100644 --- a/rplugin/python3/CopilotChat/handlers/vsplit_chat_handler.py +++ b/rplugin/python3/CopilotChat/handlers/vsplit_chat_handler.py @@ -14,6 +14,7 @@ def __init__(self, nvim: MyNvim): "filetype": "copilot-chat", }, ) + self.language = self.nvim.eval("g:copilot_chat_language") def vsplit(self): self.buffer.option("filetype", "copilot-chat") diff --git a/rplugin/python3/CopilotChat/prompts.py b/rplugin/python3/CopilotChat/prompts.py index 1290cbb0..a42a0c5f 100644 --- a/rplugin/python3/CopilotChat/prompts.py +++ b/rplugin/python3/CopilotChat/prompts.py @@ -1,3 +1,5 @@ +from string import Template + # pylint: disable=locally-disabled, multiple-statements, fixme, line-too-long COPILOT_INSTRUCTIONS = """You are an AI programming assistant. When asked for you name, you must respond with "GitHub Copilot". @@ -249,3 +251,4 @@ """ PROMPT_SIMPLE_DOCSTRING = "add simple docstring to this code" PROMPT_SEPARATE = "add comments separating the code into sections" +PROMPT_ANSWER_LANGUAGE_TEMPLATE = Template("Please answer in ${language}")