Skip to content

Commit 8e40e41

Browse files
neutrinoA4neutrinoA4jellydn
authored
feat: add language settings for copilot answers
* added answer language setting * Update rplugin/python3/CopilotChat/handlers/chat_handler.py Co-authored-by: Dung Duc Huynh (Kaka) <870029+jellydn@users.noreply.github.com> * added document to README and setup function --------- Co-authored-by: neutrinoA4 <test@test.com> Co-authored-by: Dung Duc Huynh (Kaka) <870029+jellydn@users.noreply.github.com>
1 parent fe1808e commit 8e40e41

6 files changed

Lines changed: 11 additions & 0 deletions

File tree

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ return {
3636
show_help = "yes", -- Show help text for CopilotChatInPlace, default: yes
3737
debug = false, -- Enable or disable debug mode, the log file will be in ~/.local/state/nvim/CopilotChat.nvim.log
3838
disable_extra_info = 'no', -- Disable extra information (e.g: system prompt) in the response.
39+
language = "English" -- Copilot answer language settings when using default prompts. Default language is English.
3940
-- proxy = "socks5://127.0.0.1:3000", -- Proxies requests via https or socks.
4041
},
4142
build = function()

lua/CopilotChat/init.lua

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,15 @@ _COPILOT_CHAT_GLOBAL_CONFIG = {}
1515
-- - disable_extra_info: ('yes' | 'no') default: 'yes'.
1616
-- - hide_system_prompt: ('yes' | 'no') default: 'yes'.
1717
-- - proxy: (string?) default: ''.
18+
-- - language: (string?) default: ''.
1819
-- - prompts: (table?) default: default_prompts.
1920
-- - debug: (boolean?) default: false.
2021
M.setup = function(options)
2122
vim.g.copilot_chat_show_help = options and options.show_help or 'yes'
2223
vim.g.copilot_chat_disable_separators = options and options.disable_extra_info or 'yes'
2324
vim.g.copilot_chat_hide_system_prompt = options and options.hide_system_prompt or 'yes'
2425
vim.g.copilot_chat_proxy = options and options.proxy or ''
26+
vim.g.copilot_chat_language = options and options.language or ''
2527
local debug = options and options.debug or false
2628
_COPILOT_CHAT_GLOBAL_CONFIG.debug = debug
2729

rplugin/python3/CopilotChat/handlers/chat_handler.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ def __init__(self, nvim: MyNvim, buffer: MyBuffer):
2626
self.copilot: Copilot = None
2727
self.buffer: MyBuffer = buffer
2828
self.proxy: str = os.getenv("HTTPS_PROXY") or os.getenv("ALL_PROXY") or ""
29+
self.language = self.nvim.eval("g:copilot_chat_language")
2930

3031
# public
3132

@@ -79,6 +80,8 @@ def _construct_system_prompt(self, prompt: str):
7980
system_prompt = system_prompts.COPILOT_TESTS
8081
elif prompt == system_prompts.EXPLAIN_SHORTCUT:
8182
system_prompt = system_prompts.COPILOT_EXPLAIN
83+
if self.language != "":
84+
system_prompt = system_prompt + "\n" + system_prompts.PROMPT_ANSWER_LANGUAGE_TEMPLATE.substitute(language=self.language)
8285
return system_prompt
8386

8487
def _add_start_separator(

rplugin/python3/CopilotChat/handlers/inplace_chat_handler.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ def __init__(self, nvim: MyNvim):
2020
self.diff_mode: bool = False
2121
self.model: str = MODEL_GPT4
2222
self.system_prompt: str = "SENIOR_DEVELOPER_PROMPT"
23+
self.language = self.nvim.eval("g:copilot_chat_language")
2324

2425
# Add user prompts collection
2526
self.user_prompts = self.nvim.eval("g:copilot_chat_user_prompts")

rplugin/python3/CopilotChat/handlers/vsplit_chat_handler.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ def __init__(self, nvim: MyNvim):
1414
"filetype": "copilot-chat",
1515
},
1616
)
17+
self.language = self.nvim.eval("g:copilot_chat_language")
1718

1819
def vsplit(self):
1920
self.buffer.option("filetype", "copilot-chat")

rplugin/python3/CopilotChat/prompts.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
from string import Template
2+
13
# pylint: disable=locally-disabled, multiple-statements, fixme, line-too-long
24
COPILOT_INSTRUCTIONS = """You are an AI programming assistant.
35
When asked for you name, you must respond with "GitHub Copilot".
@@ -249,3 +251,4 @@
249251
"""
250252
PROMPT_SIMPLE_DOCSTRING = "add simple docstring to this code"
251253
PROMPT_SEPARATE = "add comments separating the code into sections"
254+
PROMPT_ANSWER_LANGUAGE_TEMPLATE = Template("Please answer in ${language}")

0 commit comments

Comments
 (0)