Skip to content

Commit

Permalink
skip when unicode decode error (incomplete byte)
Browse files Browse the repository at this point in the history
  • Loading branch information
gptlang committed Feb 5, 2024
1 parent f8e9121 commit 043f6f7
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions rplugin/python3/handlers/chat_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,10 @@ def _add_chat_messages(
system_prompt, prompt, code, language=cast(str, file_type), model=model
):
buffer += token.encode("utf-8")
try:
buffer.decode("utf-8")
except UnicodeDecodeError:
continue
if "\n" in buffer.decode("utf-8"):
token = buffer.decode("utf-8").split("\n")[0]
buffer = buffer[len(token) + 1:]
Expand Down

0 comments on commit 043f6f7

Please sign in to comment.