You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
assist_should_prefill = (messages and messages[-1]["role"] == "assistant" and last_assist_msg and isinstance(last_assist_msg, str) and len(last_assist_msg.strip())>0) #avoid single character newline or space content
3115
+
last_assist_msg = ""
3116
+
if messages:
3117
+
last_assist_msg = messages[-1]["content"]
3118
+
assist_should_prefill = (messages and messages[-1]["role"] == "assistant" and last_assist_msg and isinstance(last_assist_msg, str) and len(last_assist_msg.strip())>0) #avoid single character newline or space content
3119
+
last_assist_msg = "" if not assist_should_prefill else last_assist_msg
3120
+
messages_for_render = messages[:-1] if assist_should_prefill else messages
3121
3121
if tools and len(tools)>0:
3122
-
text = jinja_compiled_template.render(messages=messages, tools=tools, add_generation_prompt=True, bos_token="", eos_token="", **chat_template_kwargs)
3122
+
text = jinja_compiled_template.render(messages=messages_for_render, tools=tools, add_generation_prompt=True, bos_token="", eos_token="", **chat_template_kwargs)
3123
3123
else:
3124
-
text = jinja_compiled_template.render(messages=messages, add_generation_prompt=True, bos_token="", eos_token="", **chat_template_kwargs)
3125
-
3126
-
if assist_should_prefill and text: # handle prefill continuations
3127
-
lastindex = text.rfind(last_assist_msg)
3128
-
if lastindex != -1:
3129
-
text = text[:lastindex + len(last_assist_msg)]
3124
+
text = jinja_compiled_template.render(messages=messages_for_render, add_generation_prompt=True, bos_token="", eos_token="", **chat_template_kwargs)
3125
+
if assist_should_prefill and text and last_assist_msg: # handle prefill continuations
0 commit comments