Skip to content

Commit 7042c24

Browse files
committed
fix
1 parent 924ef7e commit 7042c24

File tree

1 file changed

+7
-18
lines changed

1 file changed

+7
-18
lines changed

lightllm/server/api_openai.py

Lines changed: 7 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -523,24 +523,13 @@ async def _collect_generation_results(
523523
# 处理停止序列剔除
524524
final_text = "".join(final_output)
525525
if finish_reason == "stop" and sampling_params.stop_sequences.size > 0:
526-
stop_strings = sampling_params.stop_sequences.to_string()
527-
valid_stop_strings = [s for s in stop_strings if s]
528-
if valid_stop_strings:
529-
max_stop_len = len(valid_stop_strings[0])
530-
search_len = min(len(final_text), max_stop_len + 20) # 搜索长度为最长停止序列长度加20
531-
tail_text = final_text[-search_len:] if search_len > 0 else final_text
532-
tail_start_pos = len(final_text) - search_len
533-
earliest_stop_index = len(final_text)
534-
for stop_str in valid_stop_strings:
535-
stop_index = tail_text.find(stop_str)
536-
if stop_index != -1:
537-
actual_stop_index = tail_start_pos + stop_index
538-
if actual_stop_index < earliest_stop_index:
539-
earliest_stop_index = actual_stop_index
540-
541-
if earliest_stop_index < len(final_text):
542-
logger.info(f"removed stop sequence in tail: '{final_text[earliest_stop_index:]}'")
543-
final_text = final_text[:earliest_stop_index]
526+
valid_stop_strings = sampling_params.stop_sequences.to_strings()
527+
for stop_str in valid_stop_strings:
528+
stop_index = final_text.rfind(stop_str)
529+
if stop_index != -1:
530+
logger.debug(f"removed stop sequence in tail: '{final_text[stop_index:]}'")
531+
final_text = final_text[:stop_index]
532+
break
544533

545534
return {
546535
"index": prompt_index,

0 commit comments

Comments
 (0)