[FEAT] JSON constrained support (#1125)

Co-authored-by: Yineng Zhang <me@zhyncs.com>
This commit is contained in:
havetc
2024-08-26 18:37:26 +02:00
committed by GitHub
parent c5fe11a8e1
commit 9935f97b3e
10 changed files with 147 additions and 3 deletions

View File

@@ -268,7 +268,14 @@ class Req:
all_text = self.origin_input_text + self.decoded_text + jump_forward_str
all_ids = self.tokenizer.encode(all_text)
if not all_ids:
warnings.warn("Encoded all_text resulted in empty all_ids")
return False
prompt_tokens = len(self.origin_input_ids_unpadded)
if prompt_tokens > len(all_ids):
warnings.warn("prompt_tokens is larger than encoded all_ids")
return False
if all_ids[prompt_tokens - 1] != self.origin_input_ids_unpadded[-1]:
# TODO(lsyin): fix token fusion