Skip to content

Commit

Permalink
authenticate before ask
Browse files Browse the repository at this point in the history
  • Loading branch information
gptlang committed Feb 1, 2024
1 parent a298f33 commit f8823af
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
4 changes: 2 additions & 2 deletions rplugin/python3/copilot-agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ def copilot_agent_visual_cmd(self, args: list[str], range: list[int]):
self.init_vsplit_chat_handler()
if self.vsplit_chat_handler:
file_type = self.nvim.current.buffer.options["filetype"]
code_lines = self.nvim.current.buffer[range[0] - 1 : range[1]]
code_lines = self.nvim.current.buffer[range[0] - 1: range[1]]
code = "\n".join(code_lines)
self.vsplit_chat_handler.vsplit()
self.vsplit_chat_handler.chat(args[0], file_type, code)
Expand All @@ -58,7 +58,7 @@ def inplace_cmd(self, args: list[str], range: list[int]):
self.init_inplace_chat_handler()
if self.inplace_chat_handler:
file_type = self.nvim.current.buffer.options["filetype"]
code_lines = self.nvim.current.buffer[range[0] - 1 : range[1]]
code_lines = self.nvim.current.buffer[range[0] - 1: range[1]]
code = "\n".join(code_lines)
user_buffer = self.nvim.current.buffer
self.inplace_chat_handler.mount(code, file_type, range, user_buffer)
3 changes: 2 additions & 1 deletion rplugin/python3/copilot.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
from prompt_toolkit.history import InMemoryHistory
import utilities
import typings
import prompts
from typing import List, Dict

LOGIN_HEADERS = {
Expand Down Expand Up @@ -88,6 +87,8 @@ def authenticate(self):
self.token = self.session.get(url, headers=headers).json()

def ask(self, system_prompt: str, prompt: str, code: str, language: str = ""):
if not self.token:
self.authenticate()
# If expired, reauthenticate
if self.token.get("expires_at") <= round(time.time()):
self.authenticate()
Expand Down

0 comments on commit f8823af

Please sign in to comment.