Why is this part of the default template?
This part causes problems with my opencode configuration currently:
{%- if message.role == "system" %}
{%- if not loop.first %}
{{- raise_exception('System message must be at the beginning.') }}
{%- endif %}
# ...
I just pulled the models and I am pretty excited to try the new models, but for some reason they error out with the above mentioned error is there any known workaround?
Okay I found the culprit, it is a "context management" plugin that adds a secondary system prompt message, but my question stands I think?
Yeah some companies are allergic to system messages and forbid them in the jinja template. That's quite a stupid way to go about it. But at least it's fixable.
Replace this code
{%- for message in messages %}
{%- set content = render_content(message.content, true)|trim %}
{%- if message.role == "system" %}
{%- if not loop.first %}
{{- raise_exception('System message must be at the beginning.') }}
{%- endif %}
{%- elif message.role == "user" %}
{{- '<|im_start|>' + message.role + '\n' + content + '<|im_end|>' + '\n' }}
by this one:
{%- for message in messages %}
{%- set content = render_content(message.content, true)|trim %}
{%- if message.role == "system" %}
{{- '<|im_start|>' + message.role + '\n' + content + '<|im_end|>' + '\n' }}
{%- elif message.role == "user" %}
{{- '<|im_start|>' + message.role + '\n' + content + '<|im_end|>' + '\n' }}
This deletes the check, and replace it by an insertion of the system message. No more arbitrary jinja related crashes.
(If you're loading the model using a GGUF, you'll have to setup a custom template yourself, as the default one is burnt into the file)