Skip to content

Commit

Permalink
feat: Proxy support
Browse files Browse the repository at this point in the history
  • Loading branch information
gptlang committed Feb 9, 2024
1 parent be23873 commit ab150ce
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 4 deletions.
3 changes: 1 addition & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,9 @@

## [1.0.1](https://github.com/CopilotC-Nvim/CopilotChat.nvim/compare/v1.0.0...v1.0.1) (2024-02-08)


### Bug Fixes

* multi-byte languages by manually tracking last_line_col for buf_set_text ([20a4234](https://github.com/CopilotC-Nvim/CopilotChat.nvim/commit/20a4234a542deef1a128aca4d0dd7e8d429a1f2a))
- multi-byte languages by manually tracking last_line_col for buf_set_text ([20a4234](https://github.com/CopilotC-Nvim/CopilotChat.nvim/commit/20a4234a542deef1a128aca4d0dd7e8d429a1f2a))

## 1.0.0 (2024-02-06)

Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,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.
-- proxy = "socks5://127.0.0.1:3000", -- Proxies requests via https or socks.
},
build = function()
vim.notify("Please update the remote plugins by running ':UpdateRemotePlugins', then restart Neovim.")
Expand Down
1 change: 1 addition & 0 deletions lua/CopilotChat/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ _COPILOT_CHAT_GLOBAL_CONFIG = {}
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_proxy = options and options.proxy or ''
local debug = options and options.debug or false
_COPILOT_CHAT_GLOBAL_CONFIG.debug = debug

Expand Down
5 changes: 4 additions & 1 deletion rplugin/python3/copilot.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@


class Copilot:
def __init__(self, token: str = None):
def __init__(self, token: str = None, proxy: str = None):
if token is None:
token = utilities.get_cached_token()
self.github_token = token
Expand All @@ -33,6 +33,9 @@ def __init__(self, token: str = None):

self.session = requests.Session()

if proxy:
self.session.proxies = {"https": proxy}

def request_auth(self):
url = "https://github.com/login/device/code"

Expand Down
7 changes: 6 additions & 1 deletion rplugin/python3/handlers/chat_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ def __init__(self, nvim: MyNvim, buffer: MyBuffer):
self.nvim: MyNvim = nvim
self.copilot: Copilot = None
self.buffer: MyBuffer = buffer
self.proxy: str = None

# public

Expand All @@ -41,6 +42,10 @@ def chat(
disable_separators = (
self.nvim.eval("g:copilot_chat_disable_separators") == "yes"
)
self.proxy = self.nvim.eval("g:copilot_chat_proxy")
if "://" not in self.proxy:
self.proxy = None

if system_prompt is None:
system_prompt = self._construct_system_prompt(prompt)
# Start the spinner
Expand Down Expand Up @@ -201,7 +206,7 @@ def _add_chat_messages(
self, system_prompt: str, prompt: str, code: str, file_type: str, model: str
):
if self.copilot is None:
self.copilot = Copilot()
self.copilot = Copilot(proxy=self.proxy)
if self.copilot.github_token is None:
req = self.copilot.request_auth()
self.nvim.out_write(
Expand Down

0 comments on commit ab150ce

Please sign in to comment.