diff --git a/python/mlc_chat/rest.py b/python/mlc_chat/rest.py index 2816d9bec7..e92c2824d3 100644 --- a/python/mlc_chat/rest.py +++ b/python/mlc_chat/rest.py @@ -215,6 +215,10 @@ async def iter_response(): prev_txt = "" async for content in AsyncCompletionStream(generation_config=generation_config): if content: + # Remove the replacement character (U+FFFD) from the response + # This is to handle emojis. An emoji might be made up of multiple tokens. + # In the Rest streaming setting, if an emoji gets truncated in the middle of + # its encoded byte sequence, a replacement character will appear. valid_content = content.replace("�", "") chunk = ChatCompletionStreamResponse( choices=[