From c43ae422ba0e3f9520c0735e8d0ad04e2d5185f2 Mon Sep 17 00:00:00 2001 From: neutrinoA4 Date: Sun, 18 Feb 2024 03:14:05 +0900 Subject: [PATCH 1/3] added answer language setting --- lua/CopilotChat/init.lua | 1 + rplugin/python3/CopilotChat/handlers/chat_handler.py | 3 +++ rplugin/python3/CopilotChat/handlers/inplace_chat_handler.py | 1 + rplugin/python3/CopilotChat/handlers/vsplit_chat_handler.py | 1 + rplugin/python3/CopilotChat/prompts.py | 3 +++ 5 files changed, 9 insertions(+) diff --git a/lua/CopilotChat/init.lua b/lua/CopilotChat/init.lua index e80fd184..6b341d69 100644 --- a/lua/CopilotChat/init.lua +++ b/lua/CopilotChat/init.lua @@ -22,6 +22,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..cd8ef4f1 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_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}") From 51f8565c4187eae9f4eee38e9f628831ae69324c Mon Sep 17 00:00:00 2001 From: neutrinoA4 <122616073+neutrinoA4@users.noreply.github.com> Date: Sun, 18 Feb 2024 04:01:59 +0900 Subject: [PATCH 2/3] Update rplugin/python3/CopilotChat/handlers/chat_handler.py Co-authored-by: Dung Duc Huynh (Kaka) <870029+jellydn@users.noreply.github.com> --- rplugin/python3/CopilotChat/handlers/chat_handler.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rplugin/python3/CopilotChat/handlers/chat_handler.py b/rplugin/python3/CopilotChat/handlers/chat_handler.py index cd8ef4f1..f643614a 100644 --- a/rplugin/python3/CopilotChat/handlers/chat_handler.py +++ b/rplugin/python3/CopilotChat/handlers/chat_handler.py @@ -81,7 +81,7 @@ def _construct_system_prompt(self, prompt: str): elif prompt == system_prompts.EXPLAIN_SHORTCUT: system_prompt = system_prompts.COPILOT_EXPLAIN if self.language != "": - system_prompt = system_prompts.PROMPT_ANSWER_LANGUAGE_TEMPLATE.substitute(language=self.language) + system_prompt = system_prompt + "\n" + system_prompts.PROMPT_ANSWER_LANGUAGE_TEMPLATE.substitute(language=self.language) return system_prompt def _add_start_separator( From 2907e39c43bdefe95e651c69934b3cb7079506e8 Mon Sep 17 00:00:00 2001 From: neutrinoA4 Date: Sun, 18 Feb 2024 04:18:56 +0900 Subject: [PATCH 3/3] added document to README and setup function --- README.md | 1 + lua/CopilotChat/init.lua | 1 + 2 files changed, 2 insertions(+) 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 6b341d69..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)