Skip to content

Commit

Permalink
feat: support template's stop_str as list (#2678)
Browse files Browse the repository at this point in the history
  • Loading branch information
congchan authored Nov 13, 2023
1 parent a333a55 commit aeec0e0
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion fastchat/llm_judge/gen_model_answer.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,8 +141,19 @@ def get_model_answers(
output_ids,
spaces_between_special_tokens=False,
)
if conv.stop_str and output.find(conv.stop_str) > 0:
if conv.stop_str and isinstance(conv.stop_str, list):
stop_str_indices = sorted(
[
output.find(stop_str)
for stop_str in conv.stop_str
if output.find(stop_str) > 0
]
)
if len(stop_str_indices) > 0:
output = output[: stop_str_indices[0]]
elif conv.stop_str and output.find(conv.stop_str) > 0:
output = output[: output.find(conv.stop_str)]

for special_token in tokenizer.special_tokens_map.values():
if isinstance(special_token, list):
for special_tok in special_token:
Expand Down

0 comments on commit aeec0e0

Please sign in to comment.