Jinja模板 writeor的博客 wr的小窝喔~
  • 欢迎访问wr的小窝~,推荐使用最新版火狐浏览器和Chrome浏览器访问本网站.
  • 如果您觉得本站非常有看点,那么赶紧使用Ctrl+D 收藏吧
  • 嘟嘟嘟嘟嘟嘟啦~~

Jinja模板

未分类 writeor 6个月前 (03-22) 174次浏览 已收录 0个评论

{%- if not messages %}{{- raise_exception(‘No messages provided.’) }}{%- endif %}

{# 系统消息 #}
{%- if messages[0].role == ‘system’ %}{{- ‘<|im_start|>system\n’ + messages[0].content + ‘<|im_end|>\n’ }}{%- endif %}

{# 处理每条消息 #}
{%- for message in messages %}
{%- if message.role == ‘system’ and not loop.first %}{{- raise_exception(‘System message must be at the beginning.’) }}{%- endif %}
{%- if message.role == ‘user’ %}{{- ‘<|im_start|>user\n’ + message.content + ‘<|im_end|>\n’ }}
{%- elif message.role == ‘assistant’ %}
{{- ‘<|im_start|>assistant\n’ + message.content }}
{%- if message.tool_calls and message.tool_calls is iterable %}
{%- for tc in message.tool_calls %}
{%- set tc_func = tc.function if tc.function is defined else tc %}
{{- ‘\n\n’ }}
{%- if tc_func.arguments is mapping %}
{%- for key in tc_func.arguments %}
{{- ‘\n’ + tc_func.arguments[key]|string + ‘\n\n’ }}
{%- endfor %}
{%- elif tc_func.arguments is string %}
{{- tc_func.arguments }}
{%- endif %}
{{- ‘\n
‘ }}
{%- endfor %}
{%- endif %}
{{- ‘<|im_end|>\n’ }}
{%- elif message.role == ‘tool’ %}
{{- ‘<|im_start|>user\n\n’ + message.content + ‘\n<|im_end|>\n’ }}
{%- endif %}
{%- endfor %}

{# 生成提示 #}
{%- if add_generation_prompt %}{{- ‘<|im_start|>assistant\n’ }}{%- endif %}


wr的小窝 , 版权所有丨如未注明 , 均为原创丨本网站采用BY-NC-SA协议进行授权
转载请注明原文链接:Jinja模板
喜欢 (0)
[[email protected]]
分享 (0)

您必须 登录 才能发表评论!