[Bugfix][Frontend] Detokenize echoed prompts after truncation (#61876)

Signed-off-by: Cy <15118312+cycancode@users.noreply.github.com>
Co-authored-by: Cy <15118312+cycancode@users.noreply.github.com>
This commit is contained in:
Cy Cheng
2026-10-17 05:20:38 +00:00
committed by GitHub
co-authored by Cy
parent 39983a5e7a
commit d74f4180cd
2 changed files with 37 additions and 2 deletions
+10 -2
View File
@@ -687,13 +687,17 @@ class BaseRenderer(ABC, Generic[_T]):
prompt = self._tokenize_prompt(prompt, params)
prompt = self._apply_prompt_char_offset(prompt, prompt_char_offset)
prompt = params.apply_post_tokenization(self.tokenizer, prompt) # type: ignore[arg-type]
# Detokenize after truncation so the text matches the tokens sent
# to the engine.
if params.needs_detokenization and "prompt" not in prompt:
if "prompt_token_ids" not in prompt:
raise RuntimeError("Cannot run detokenization on embeddings")
prompt = self._detokenize_prompt(prompt) # type: ignore[arg-type]
return params.apply_post_tokenization(self.tokenizer, prompt) # type: ignore[arg-type]
return prompt
@overload
async def _tokenize_singleton_prompt_async(
@@ -727,13 +731,17 @@ class BaseRenderer(ABC, Generic[_T]):
prompt = await self._tokenize_prompt_async(prompt, params)
prompt = self._apply_prompt_char_offset(prompt, prompt_char_offset)
prompt = params.apply_post_tokenization(self.tokenizer, prompt) # type: ignore[arg-type]
# Detokenize after truncation so the text matches the tokens sent
# to the engine.
if params.needs_detokenization and "prompt" not in prompt:
if "prompt_token_ids" not in prompt:
raise RuntimeError("Cannot run detokenization on embeddings")
prompt = await self._detokenize_prompt_async(prompt) # type: ignore[arg-type]
return params.apply_post_tokenization(self.tokenizer, prompt) # type: ignore[arg-type]
return prompt
def _tokenize_enc_dec_prompt(
self,