Skip to content

Commit

Permalink
Improve Chinese character streaming when the last char is half Chines…
Browse files Browse the repository at this point in the history
…e word. (#95)
  • Loading branch information
haotian-liu authored Jan 24, 2024
1 parent 01ee0fb commit d3fc86a
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions python/sglang/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,9 @@ def find_printable_text(text):
# If the last token is a CJK character, we print the characters.
elif len(text) > 0 and _is_chinese_char(ord(text[-1])):
return text
# Otherwise if the penultimate token is a CJK character, we print the characters except for the last one.
elif len(text) > 1 and _is_chinese_char(ord(text[-2])):
return text[:-1]
# Otherwise, prints until the last space char (simple heuristic to avoid printing incomplete words,
# which may change with the subsequent token -- there are probably smarter ways to do this!)
else:
Expand Down

0 comments on commit d3fc86a

Please sign in to comment.