PEFT
Safetensors
English
gemma3_text
tactical-intelligence
vanta-research
scout-8b
conversational
conversational-ai
large-language-model
text-generation-inference
research
roleplay
chat
chat-ai
chatbot
reasoning
logic
science
STEM
constraint-aware
ai-research
ai-alignment-research
ai-alignment
ai-behavior
ai-behavior-research
| {%- set ns = namespace(multi_step_tool=true, last_query_index=messages|length - 1) -%} | |
| {%- set emit = namespace(started=false) -%} | |
| {# ---------- Build base system message (always emitted) ---------- #} | |
| {%- set base_system = 'You are rnj-1, a foundation model trained by Essential AI.\n' -%} | |
| {# ---------- Optional tools preface as a synthetic system message ---------- #} | |
| {%- if tools %} | |
| {%- set sys_preamble -%} | |
| # Tools | |
| You may call one or more functions to assist with the user query. | |
| You are provided with function signatures within <tools></tools> XML tags: | |
| <tools> | |
| {%- for tool in tools %} | |
| {{ "\n" ~ (tool | tojson) }} | |
| {% endfor %} | |
| </tools> | |
| For each function call, return a json object with function name and arguments within <tool_call></tool_call> XML tags: | |
| <tool_call> | |
| {"name": <function-name>, "arguments": <args-json-object>} | |
| </tool_call> | |
| {%- endset -%} | |
| {# If the first user-provided message is system, include it above the tools preface #} | |
| {%- set combined_system = (messages and messages[0].role == 'system') | |
| and (messages[0].content is string) -%} | |
| {%- set sys_content = (combined_system and (messages[0].content ~ "\n\n" ~ sys_preamble)) or sys_preamble -%} | |
| {%- set content = '<|start_header_id|>system<|end_header_id|>\n' ~ base_system ~ '\n' ~ sys_content ~ '<|eot_id|>' -%} | |
| {%- if not emit.started -%}{%- set content = bos_token ~ content -%}{%- set emit.started = true -%}{%- endif -%} | |
| {{- content -}} | |
| {%- else %} | |
| {# No tools: always emit base_system, and include user's system message if present #} | |
| {%- set user_system_content = '' -%} | |
| {%- if messages and messages[0].role == 'system' and (messages[0].content is string) -%} | |
| {%- set user_system_content = '\n' ~ messages[0].content -%} | |
| {%- endif -%} | |
| {%- set content = '<|start_header_id|>system<|end_header_id|>\n' ~ base_system ~ user_system_content ~ '<|eot_id|>' -%} | |
| {%- if not emit.started -%}{%- set content = bos_token ~ content -%}{%- set emit.started = true -%}{%- endif -%} | |
| {{- content -}} | |
| {%- endif -%} | |
| {# ---------- Locate last user query for multi-step tool behavior ---------- #} | |
| {%- for message in messages[::-1] %} | |
| {%- set index = (messages|length - 1) - loop.index0 -%} | |
| {%- if ns.multi_step_tool | |
| and message.role == "user" | |
| and message.content is string | |
| and not (message.content.startswith('<tool_response>') and message.content.endswith('</tool_response>')) -%} | |
| {%- set ns.multi_step_tool = false -%} | |
| {%- set ns.last_query_index = index -%} | |
| {%- endif -%} | |
| {%- endfor -%} | |
| {# ---------- Walk all messages and emit in Llama-3 format ---------- #} | |
| {%- for message in messages %} | |
| {# normalize content #} | |
| {%- if message.content is string -%} | |
| {%- set content = message.content -%} | |
| {%- else -%} | |
| {%- set content = '' -%} | |
| {%- endif -%} | |
| {# --- user/system (non-initial system already handled above) --- #} | |
| {%- if (message.role == "user") or (message.role == "system" and not loop.first) -%} | |
| {%- set block = '<|start_header_id|>' ~ message.role ~ '<|end_header_id|>\n' ~ content ~ '<|eot_id|>' -%} | |
| {%- if not emit.started -%}{%- set block = bos_token ~ block -%}{%- set emit.started = true -%}{%- endif -%} | |
| {{- block -}} | |
| {# --- assistant --- #} | |
| {%- elif message.role == "assistant" -%} | |
| {%- set body = content -%} | |
| {%- set header = '<|start_header_id|>assistant<|end_header_id|>\n' -%} | |
| {%- if not emit.started -%}{{ bos_token }}{%- set emit.started = true -%}{%- endif -%} | |
| {{- header -}} | |
| {% generation %} | |
| {{- body -}} | |
| {%- if message.tool_calls -%} | |
| {%- for tool_call in message.tool_calls -%} | |
| {%- if tool_call.function -%}{%- set tc = tool_call.function -%}{%- else -%}{%- set tc = tool_call -%}{%- endif -%} | |
| {%- set args_json = (tc.arguments if (tc.arguments is string) else (tc.arguments | tojson)) -%} | |
| {%- if loop.first -%} | |
| {{- '<tool_call>\n{"name": "' ~ tc.name ~ '", "arguments": ' ~ args_json ~ '}\n</tool_call>' -}} | |
| {%- else -%} | |
| {{- '\n<tool_call>\n{"name": "' ~ tc.name ~ '", "arguments": ' ~ args_json ~ '}\n</tool_call>' -}} | |
| {%- endif -%} | |
| {%- endfor -%} | |
| {%- endif -%} | |
| {{- '<|eot_id|>' -}}{%- endgeneration -%} | |
| {# --- tool messages are wrapped as synthetic user messages with <tool_response> --- #} | |
| {%- elif message.role == "tool" -%} | |
| {%- set open_user = (loop.first or (loop.index0 > 0 and messages[loop.index0 - 1].role != "tool")) -%} | |
| {%- set close_user = (loop.last or (loop.index0 < messages|length - 1 and messages[loop.index0 + 1].role != "tool")) -%} | |
| {%- if open_user -%} | |
| {%- set header = '<|start_header_id|>user<|end_header_id|>\n' -%} | |
| {%- if not emit.started -%}{%- set header = bos_token ~ header -%}{%- set emit.started = true -%}{%- endif -%} | |
| {{- header -}} | |
| {%- endif -%} | |
| {%- if open_user -%} | |
| {{- '<tool_response>\n' -}} | |
| {%- else -%} | |
| {{- '\n<tool_response>\n' -}} | |
| {%- endif -%} | |
| {{- content -}} | |
| {{- '\n</tool_response>' -}} | |
| {%- if close_user -%} | |
| {{- '<|eot_id|>' -}} | |
| {%- endif -%} | |
| {%- endif -%} | |
| {%- endfor -%} | |
| {# ---------- Add generation prompt header for the model to continue ---------- #} | |
| {%- if add_generation_prompt -%} | |
| {%- set tail = '<|start_header_id|>assistant<|end_header_id|>\n' -%} | |
| {{- tail -}} | |
| {%- endif -%} |