Skip to content

Commit

Permalink
add option to remove extra information: disable_extra_info
Browse files Browse the repository at this point in the history
  • Loading branch information
gptlang committed Feb 4, 2024
1 parent 0334067 commit dbd77cc
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 8 deletions.
1 change: 1 addition & 0 deletions lua/CopilotChat/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ _COPILOT_CHAT_GLOBAL_CONFIG = {}
-- - debug: (boolean?) default: false.
M.setup = function(options)
vim.g.copilot_chat_show_help = options and options.show_help or 'yes'
vim.g.copilot_chat_disable_separators = options and options.disable_extra_info or false
local debug = options and options.debug or false
_COPILOT_CHAT_GLOBAL_CONFIG.debug = debug

Expand Down
29 changes: 21 additions & 8 deletions rplugin/python3/handlers/chat_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ def chat(
):
if system_prompt is None:
system_prompt = self._construct_system_prompt(prompt)

# Start the spinner
self.nvim.exec_lua('require("CopilotChat.spinner").show()')

Expand All @@ -54,7 +53,9 @@ def chat(
self.nvim.exec_lua('require("CopilotChat.spinner").hide()')

if not disable_end_separator:
self._add_end_separator(model)
self._add_end_separator(
model, self.nvim.eval("g:copilot_chat_disable_separators") == "yes"
)

# private

Expand All @@ -75,14 +76,15 @@ def _add_start_separator(
code: str,
file_type: str,
winnr: int,
no_annoyance: bool = False,
):
if is_module_installed("tiktoken"):
if is_module_installed("tiktoken") and no_annoyance:
self._add_start_separator_with_token_count(
system_prompt, prompt, code, file_type, winnr
)
else:
self._add_regular_start_separator(
system_prompt, prompt, code, file_type, winnr
system_prompt, prompt, code, file_type, winnr, no_annoyance
)

def _add_regular_start_separator(
Expand All @@ -92,15 +94,17 @@ def _add_regular_start_separator(
code: str,
file_type: str,
winnr: int,
no_annoyance: bool = False,
):
if code:
if code and not no_annoyance:
code = f"\n \nCODE:\n```{file_type}\n{code}\n```"

last_row_before = len(self.buffer.lines())
system_prompt_height = len(system_prompt.split("\n"))
code_height = len(code.split("\n"))

start_separator = f"""### User
start_separator = (
f"""### User
SYSTEM PROMPT:
```
Expand All @@ -111,8 +115,13 @@ def _add_regular_start_separator(
### Copilot
"""
if not no_annoyance
else f"### User\n{prompt}\n\n### Copilot\n\n"
)
self.buffer.append(start_separator.split("\n"))

if no_annoyance:
return
self._add_folds(code, code_height, last_row_before, system_prompt_height, winnr)

def _add_start_separator_with_token_count(
Expand Down Expand Up @@ -222,13 +231,17 @@ def _add_chat_messages(
token.split("\n"),
)

def _add_end_separator(self, model: str):
def _add_end_separator(self, model: str, no_annoyance: bool = False):
current_datetime = datetime.now().strftime("%Y-%m-%d %H:%M:%S")
model_info = f"\n#### Answer provided by Copilot (Model: `{model}`) on {current_datetime}."
additional_instructions = (
"\n> For additional queries, please use the `CopilotChat` command."
)
disclaimer = "\n> Please be aware that the AI's output may not always be accurate. Always cross-verify the output.\n---\n"
disclaimer = "\n> Please be aware that the AI's output may not always be accurate. Always cross-verify the output."

end_message = model_info + additional_instructions + disclaimer

if no_annoyance:
end_message = "\n" + current_datetime + "\n---\n"

self.buffer.append(end_message.split("\n"))

0 comments on commit dbd77cc

Please sign in to comment.