cjk pr minor cleanup

This commit is contained in:
Andrei Betlen 2023-08-29 07:21:59 -04:00
parent bae44ec8bf
commit 3f76e1de52

View file

@ -1066,14 +1066,15 @@ class Llama:
while len(remaining_tokens) > 0: while len(remaining_tokens) > 0:
decode_success = False decode_success = False
for i in range(1, len(remaining_tokens) + 1): for i in range(1, len(remaining_tokens) + 1):
tokens = remaining_tokens[:i]
try: try:
bs = self.detokenize(tokens) bs = self.detokenize(remaining_tokens[:i])
text = bs.decode('utf-8') ts = bs.decode('utf-8')
decode_success = True decode_success = True
break break
except UnicodeError: except UnicodeError:
pass pass
else:
break
if not decode_success: if not decode_success:
# all remaining tokens cannot be decoded to a UTF-8 character # all remaining tokens cannot be decoded to a UTF-8 character
break break
@ -1090,7 +1091,7 @@ class Llama:
"model": model_name, "model": model_name,
"choices": [ "choices": [
{ {
"text": text, "text": ts,
"index": 0, "index": 0,
"logprobs": None, "logprobs": None,
"finish_reason": None, "finish_reason": None,