diff --git a/rplugin/python3/handlers/chat_handler.py b/rplugin/python3/handlers/chat_handler.py index e42239be..f5e8aaa2 100644 --- a/rplugin/python3/handlers/chat_handler.py +++ b/rplugin/python3/handlers/chat_handler.py @@ -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:]