"vscode:/vscode.git/clone" did not exist on "ca81ff5196b2fa82b7a9d553cd6e30eab9e72aca"
Unverified Commit de111f32 authored by Yufeng He's avatar Yufeng He Committed by GitHub
Browse files

[Bugfix] Fix bench_serve UTF-8 decode crash on split multi-byte chars (#38732)

parent afabb5f4
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
# SPDX-FileCopyrightText: Copyright contributors to the vLLM project # SPDX-FileCopyrightText: Copyright contributors to the vLLM project
"""The request function for API endpoints.""" """The request function for API endpoints."""
import codecs
import io import io
import json import json
import os import os
...@@ -25,11 +26,12 @@ class StreamedResponseHandler: ...@@ -25,11 +26,12 @@ class StreamedResponseHandler:
def __init__(self): def __init__(self):
self.buffer = "" self.buffer = ""
self._decoder = codecs.getincrementaldecoder("utf-8")()
def add_chunk(self, chunk_bytes: bytes) -> list[str]: def add_chunk(self, chunk_bytes: bytes) -> list[str]:
"""Add a chunk of bytes to the buffer and return any complete """Add a chunk of bytes to the buffer and return any complete
messages.""" messages."""
chunk_str = chunk_bytes.decode("utf-8") chunk_str = self._decoder.decode(chunk_bytes)
self.buffer += chunk_str self.buffer += chunk_str
messages = [] messages = []
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment