Skip to content

Commit

Permalink
feat: add options to hide system prompts
Browse files Browse the repository at this point in the history
  • Loading branch information
jellydn committed Feb 16, 2024
1 parent 25ea586 commit 98a6191
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 0 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,9 @@ You have the ability to tailor this plugin to your specific needs using the conf
{
debug = false, -- Enable or disable debug mode
show_help = 'yes', -- Show help text for CopilotChatInPlace
disable_extra_info = 'no', -- Disable extra information in the response
hide_system_prompt = 'yes', -- Hide system prompts in the response
proxy = '', -- Proxies requests via https or socks
prompts = { -- Set dynamic prompts for CopilotChat commands
Explain = 'Explain how it works.',
Tests = 'Briefly explain how the selected code works, then generate unit tests.',
Expand Down
3 changes: 3 additions & 0 deletions lua/CopilotChat/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,14 @@ _COPILOT_CHAT_GLOBAL_CONFIG = {}
---@param options (table | nil)
-- - show_help: ('yes' | 'no') default: 'yes'.
-- - disable_extra_info: ('yes' | 'no') default: 'yes'.
-- - hide_system_prompt: ('yes' | 'no') default: 'yes'.
-- - proxy: (string?) default: ''.
-- - prompts: (table?) default: default_prompts.
-- - 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 '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 ''
local debug = options and options.debug or false
_COPILOT_CHAT_GLOBAL_CONFIG.debug = debug
Expand Down
13 changes: 13 additions & 0 deletions rplugin/python3/CopilotChat/handlers/chat_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,13 @@ def _add_regular_start_separator(
winnr: int,
no_annoyance: bool = False,
):
hide_system_prompt = (
self.nvim.eval("g:copilot_chat_hide_system_prompt") == "yes"
)

if hide_system_prompt:
system_prompt = "...System prompt hidden..."

if code and not no_annoyance:
code = f"\n \nCODE:\n```{file_type}\n{code}\n```"

Expand Down Expand Up @@ -148,11 +155,17 @@ def _add_start_separator_with_token_count(

encoding = tiktoken.encoding_for_model("gpt-4")

hide_system_prompt = (
self.nvim.eval("g:copilot_chat_hide_system_prompt") == "yes"
)
num_total_tokens = len(encoding.encode(f"{system_prompt}\n{prompt}\n{code}"))
num_system_tokens = len(encoding.encode(system_prompt))
num_prompt_tokens = len(encoding.encode(prompt))
num_code_tokens = len(encoding.encode(code))

if hide_system_prompt:
system_prompt = "... System prompt hidden ..."

if code:
code = f"\n \nCODE: {num_code_tokens} Tokens \n```{file_type}\n{code}\n```"

Expand Down

0 comments on commit 98a6191

Please sign in to comment.