Skip to content

Commit

Permalink
[Rest] Fix emoji handling in Rest API. (mlc-ai#1142)
Browse files Browse the repository at this point in the history
  • Loading branch information
YuchenJin authored Oct 30, 2023
1 parent b190578 commit 8ca0176
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions python/mlc_chat/rest.py
Original file line number Diff line number Diff line change
Expand Up @@ -215,18 +215,19 @@ async def iter_response():
prev_txt = ""
async for content in AsyncCompletionStream(generation_config=generation_config):
if content:
valid_content = content.replace("�", "")
chunk = ChatCompletionStreamResponse(
choices=[
ChatCompletionResponseStreamChoice(
index=0,
delta=DeltaMessage(
role="assistant", content=content[len(prev_txt) :]
role="assistant", content=valid_content[len(prev_txt) :]
),
finish_reason="stop",
)
]
)
prev_txt = content
prev_txt = valid_content
yield f"data: {chunk.json(exclude_unset=True)}\n\n"

return StreamingResponse(iter_response(), media_type="text/event-stream")
Expand Down

0 comments on commit 8ca0176

Please sign in to comment.