Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Proxy support #36

Merged
merged 2 commits into from
Feb 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
8 changes: 7 additions & 1 deletion rplugin/python3/handlers/chat_handler.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import time
from datetime import datetime
from typing import Optional, cast
import os

import prompts as system_prompts
from copilot import Copilot
Expand All @@ -24,6 +25,7 @@ def __init__(self, nvim: MyNvim, buffer: MyBuffer):
self.nvim: MyNvim = nvim
self.copilot: Copilot = None
self.buffer: MyBuffer = buffer
self.proxy: str = os.getenv("HTTPS_PROXY") or os.getenv("ALL_PROXY") or ""

# public

Expand All @@ -41,6 +43,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 +207,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
Loading