Skip to content

Commit

Permalink
fix merge conflicts
Browse files Browse the repository at this point in the history
  • Loading branch information
gptlang committed Feb 8, 2024
1 parent 9022532 commit 37ae9a5
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 6 deletions.
7 changes: 4 additions & 3 deletions rplugin/python3/copilot.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,10 +127,11 @@ def ask(
)
)
for line in response.iter_lines():
line = line.decode("utf-8").replace("data: ", "").strip()
if line.startswith("[DONE]"):
line: bytes = line
line = line.replace(b"data: ", b"")
if line.startswith(b"[DONE]"):
break
elif line == "":
elif line == b"":
continue
try:
line = json.loads(line)
Expand Down
18 changes: 15 additions & 3 deletions rplugin/python3/handlers/chat_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,8 @@ def _add_chat_messages(
if self.copilot.github_token is None:
req = self.copilot.request_auth()
self.nvim.out_write(
f"Please visit {req['verification_uri']} and enter the code {req['user_code']}\n"
f"Please visit {req['verification_uri']
} and enter the code {req['user_code']}\n"
)
current_time = time.time()
wait_until = current_time + req["expires_in"]
Expand All @@ -215,10 +216,21 @@ def _add_chat_messages(
return
self.nvim.out_write("Successfully authenticated with Copilot\n")
self.copilot.authenticate()

buffer = ""
for token in self.copilot.ask(
system_prompt, prompt, code, language=cast(str, file_type), model=model
):
buffer += token
# Look for the last newline in buffer
last_newline = buffer.rfind("\n")
# If there is no newline, then continue
if last_newline == -1:
continue
# If there is a newline, take everything in front of it and set that as the token
token = buffer[: last_newline + 1]

# Remove the token and newline from the buffer
buffer = buffer.replace(token, "")
self.nvim.exec_lua(
'require("CopilotChat.utils").log_info(...)', f"Token: {token}"
)
Expand All @@ -232,7 +244,7 @@ def _add_chat_messages(
last_line_col,
last_line_row,
last_line_col,
token.split("\n"),
[tok.encode('utf-8') for tok in token.split("\n")],
)

def _add_end_separator(self, model: str, disable_separators: bool = False):
Expand Down

0 comments on commit 37ae9a5

Please sign in to comment.