Browse Source

fix: do not expose EOS token in the API

AlpinDale 7 months ago
parent
commit
6785d78d82
1 changed files with 5 additions and 0 deletions
  1. 5 0
      aphrodite/engine/output_processor/stop_checker.py

+ 5 - 0
aphrodite/engine/output_processor/stop_checker.py

@@ -48,6 +48,11 @@ class StopChecker:
         # Check if the sequence has generated the EOS token.
         if ((not sampling_params.ignore_eos)
                 and seq.get_last_token_id() == seq.eos_token_id):
+            # Remove the last EOS token unless explicitly specified
+            # This prevents unintended exposure of the EOS token
+            if new_char_count and (
+                    not sampling_params.include_stop_str_in_output):
+                seq.output_text = seq.output_text[:-new_char_count]
             seq.status = SequenceStatus.FINISHED_STOPPED
             return