97 lines
3.9 KiB
Plaintext
97 lines
3.9 KiB
Plaintext
|
|
{# ---------------------------
|
||
|
|
Header: identity + tools
|
||
|
|
--------------------------- #}
|
||
|
|
{{- '<|im_start|>developer\n' -}}
|
||
|
|
{%- if model_identity -%}
|
||
|
|
{{ model_identity }}
|
||
|
|
{%- else -%}
|
||
|
|
You are a large language model trained by Menhera.org.
|
||
|
|
{%- endif -%}
|
||
|
|
|
||
|
|
{%- if tools and tools|length > 0 -%}
|
||
|
|
{{ "\n\n# Tools\n\nYou may call one or more functions to assist with the user query.\n\nYou are provided with function signatures within <tools></tools> XML tags:\n<tools>" }}
|
||
|
|
{%- for tool in tools -%}
|
||
|
|
{{ "\n" }}{{ tool | tojson }}
|
||
|
|
{%- endfor -%}
|
||
|
|
{{ "\n</tools>\n\nWhen you decide to call a tool, output one or more tool calls using <tool_call></tool_call> tags.\n\nEach tool call must be a JSON object in the following OpenAI-compatible shape:\n<tool_call>\n{\n \"id\": \"call_...\",\n \"type\": \"function\",\n \"function\": {\n \"name\": \"<function-name>\",\n \"arguments\": \"<JSON-string>\"\n }\n}\n</tool_call>\n\nNotes:\n- \"arguments\" MUST be a JSON-encoded string (not an object).\n- You may emit multiple <tool_call> blocks in a single assistant turn.\n- After tool calls, you will receive tool results in <tool_response> blocks.\n- Then continue the conversation.\n" }}
|
||
|
|
{%- endif -%}
|
||
|
|
|
||
|
|
{%- if schema -%}
|
||
|
|
{{ '\n\n# Schema\n\nYou must follow the following JSON schema when you output the result. Only output the plain JSON.\n\n<schema>\n'}}
|
||
|
|
{{- schema }}
|
||
|
|
{{ '\n</schema>' }}
|
||
|
|
{%- endif -%}
|
||
|
|
{{- '<|im_end|>\n' -}}
|
||
|
|
|
||
|
|
{# ---------------------------
|
||
|
|
Conversation history
|
||
|
|
--------------------------- #}
|
||
|
|
{%- for message in messages -%}
|
||
|
|
|
||
|
|
{# 1) system/user/assistant without tool_calls #}
|
||
|
|
{%- if (message.role == "system") or (message.role == "user") or (message.role == "assistant" and not message.tool_calls) -%}
|
||
|
|
{%- set speaker = (message.name if message.name is defined else message.role) -%}
|
||
|
|
{{- '<|im_start|>' ~ message.role ~ '\n[' ~ speaker ~ ']\n' -}}
|
||
|
|
{{- message.content -}}
|
||
|
|
{{- '<|im_end|>\n' -}}
|
||
|
|
|
||
|
|
{# 2) assistant WITH tool_calls (OpenAI shape) #}
|
||
|
|
{%- elif message.role == "assistant" -%}
|
||
|
|
{%- set speaker = (message.name if message.name is defined else "assistant") -%}
|
||
|
|
{{- '<|im_start|>assistant\n[' ~ speaker ~ ']\n' -}}
|
||
|
|
{%- if message.content -%}
|
||
|
|
{{- message.content -}}
|
||
|
|
{%- endif -%}
|
||
|
|
|
||
|
|
{%- for tc in message.tool_calls -%}
|
||
|
|
{%- set fn = (tc.function if tc.function is defined else none) -%}
|
||
|
|
{%- if fn is not none -%}
|
||
|
|
{{- '\n<tool_call>\n' -}}
|
||
|
|
{{- '{' -}}
|
||
|
|
{{- '"id": ' ~ (tc.id | tojson) ~ ', ' -}}
|
||
|
|
{{- '"type": "function", ' -}}
|
||
|
|
{{- '"function": {' -}}
|
||
|
|
{{- '"name": ' ~ (fn.name | tojson) ~ ', ' -}}
|
||
|
|
{# fn.arguments should already be a JSON STRING per OpenAI spec #}
|
||
|
|
{{- '"arguments": ' ~ (fn.arguments | tojson) -}}
|
||
|
|
{{- '}' -}}
|
||
|
|
{{- '}' -}}
|
||
|
|
{{- '\n</tool_call>' -}}
|
||
|
|
{%- else -%}
|
||
|
|
{# If someone stored a simplified toolcall shape by mistake, fail safe #}
|
||
|
|
{{- '\n<tool_call>\n' -}}
|
||
|
|
{{- tc | tojson -}}
|
||
|
|
{{- '\n</tool_call>' -}}
|
||
|
|
{%- endif -%}
|
||
|
|
{%- endfor -%}
|
||
|
|
|
||
|
|
{{- '<|im_end|>\n' -}}
|
||
|
|
|
||
|
|
{# 3) tool messages: must include tool_call_id (OpenAI style) #}
|
||
|
|
{%- elif message.role == "tool" -%}
|
||
|
|
{%- if (loop.index0 == 0) or (messages[loop.index0 - 1].role != "tool") -%}
|
||
|
|
{{- '<|im_start|>tool\n' -}}
|
||
|
|
{%- endif -%}
|
||
|
|
{{- '<tool_response>\n' -}}
|
||
|
|
{{- '{' -}}
|
||
|
|
{%- if message.tool_call_id is defined -%}
|
||
|
|
{{- '"tool_call_id": ' ~ (message.tool_call_id | tojson) ~ ', ' -}}
|
||
|
|
{%- endif -%}
|
||
|
|
{{- '"content": ' ~ (message.content | tojson) -}}
|
||
|
|
{{- '}' -}}
|
||
|
|
{{- '\n</tool_response>\n' -}}
|
||
|
|
{%- if loop.last or (messages[loop.index0 + 1].role != "tool") -%}
|
||
|
|
{{- '<|im_end|>\n' -}}
|
||
|
|
{%- endif -%}
|
||
|
|
|
||
|
|
{%- endif -%}
|
||
|
|
|
||
|
|
{%- endfor -%}
|
||
|
|
|
||
|
|
{# ---------------------------
|
||
|
|
Generation prompt
|
||
|
|
--------------------------- #}
|
||
|
|
{%- if add_generation_prompt -%}
|
||
|
|
{{- '<|im_start|>assistant\n[assistant]\n' -}}
|
||
|
|
{%- endif -%}
|