Text Generation
Transformers
Safetensors
English
Chinese
qwen3_5_moe
Merge
ties
dare
Mixture of Experts
qwen
qwen3.5
qwen3.6
causal-lm
deltanet
agentic
reasoning
code
conversational
Instructions to use pragmaticcs/SignOfFour with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use pragmaticcs/SignOfFour with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="pragmaticcs/SignOfFour") messages = [ {"role": "user", "content": "Who are you?"}, ] pipe(messages)# Load model directly from transformers import AutoProcessor, AutoModelForCausalLM processor = AutoProcessor.from_pretrained("pragmaticcs/SignOfFour") model = AutoModelForCausalLM.from_pretrained("pragmaticcs/SignOfFour", device_map="auto") messages = [ {"role": "user", "content": "Who are you?"}, ] inputs = processor.apply_chat_template( messages, add_generation_prompt=True, tokenize=True, return_dict=True, return_tensors="pt", ).to(model.device) outputs = model.generate(**inputs, max_new_tokens=40) print(processor.decode(outputs[0][inputs["input_ids"].shape[-1]:])) - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- vLLM
How to use pragmaticcs/SignOfFour with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "pragmaticcs/SignOfFour" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "pragmaticcs/SignOfFour", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }'Use Docker
docker model run hf.co/pragmaticcs/SignOfFour
- SGLang
How to use pragmaticcs/SignOfFour with SGLang:
Install from pip and serve model
# Install SGLang from pip: pip install sglang # Start the SGLang server: python3 -m sglang.launch_server \ --model-path "pragmaticcs/SignOfFour" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "pragmaticcs/SignOfFour", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }'Use Docker images
docker run --gpus all \ --shm-size 32g \ -p 30000:30000 \ -v ~/.cache/huggingface:/root/.cache/huggingface \ --env "HF_TOKEN=<secret>" \ --ipc=host \ lmsysorg/sglang:latest \ python3 -m sglang.launch_server \ --model-path "pragmaticcs/SignOfFour" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "pragmaticcs/SignOfFour", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }' - Docker Model Runner
How to use pragmaticcs/SignOfFour with Docker Model Runner:
docker model run hf.co/pragmaticcs/SignOfFour
Update chat template in tokenizer_config.json and chat_template.jinja
Browse files- chat_template.jinja +406 -96
- tokenizer_config.json +2 -2
chat_template.jinja
CHANGED
|
@@ -1,36 +1,130 @@
|
|
|
|
|
|
|
|
| 1 |
{%- set image_count = namespace(value=0) %}
|
| 2 |
{%- set video_count = namespace(value=0) %}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3 |
{%- macro render_content(content, do_vision_count, is_system_content=false) %}
|
| 4 |
{%- if content is string %}
|
| 5 |
{{- content }}
|
| 6 |
{%- elif content is iterable and content is not mapping %}
|
| 7 |
{%- for item in content %}
|
| 8 |
-
{%- if
|
| 9 |
-
{%- if
|
| 10 |
-
{
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
{%-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
{
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
{%-
|
| 21 |
-
{
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
{%-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
{
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 28 |
{%- endif %}
|
| 29 |
-
{{- '<|vision_start|><|video_pad|><|vision_end|>' }}
|
| 30 |
-
{%- elif 'text' in item %}
|
| 31 |
-
{{- item.text }}
|
| 32 |
{%- else %}
|
| 33 |
-
{{-
|
| 34 |
{%- endif %}
|
| 35 |
{%- endfor %}
|
| 36 |
{%- elif content is none or content is undefined %}
|
|
@@ -39,119 +133,335 @@
|
|
| 39 |
{{- raise_exception('Unexpected content type.') }}
|
| 40 |
{%- endif %}
|
| 41 |
{%- endmacro %}
|
| 42 |
-
{%- if messages %}
|
| 43 |
-
{
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 44 |
{{- '<|im_start|>system\n' }}
|
| 45 |
-
{
|
|
|
|
|
|
|
|
|
|
| 46 |
{%- for tool in tools %}
|
| 47 |
-
{{-
|
| 48 |
{{- tool | tojson }}
|
| 49 |
{%- endfor %}
|
| 50 |
-
{{-
|
| 51 |
-
{
|
| 52 |
-
|
| 53 |
-
|
| 54 |
-
{%- if
|
| 55 |
-
|
| 56 |
-
|
|
|
|
| 57 |
{%- endif %}
|
| 58 |
{{- '<|im_end|>\n' }}
|
| 59 |
{%- else %}
|
| 60 |
-
{%- if
|
| 61 |
-
{
|
| 62 |
-
|
|
|
|
| 63 |
{%- endif %}
|
| 64 |
{%- endif %}
|
| 65 |
-
{%- set
|
| 66 |
-
{%-
|
| 67 |
-
|
| 68 |
-
{%-
|
| 69 |
-
|
| 70 |
-
{%-
|
|
|
|
| 71 |
{%- set ns.multi_step_tool = false %}
|
| 72 |
{%- set ns.last_query_index = index %}
|
| 73 |
{%- endif %}
|
| 74 |
{%- endif %}
|
| 75 |
{%- endfor %}
|
| 76 |
-
{%-
|
| 77 |
-
{%-
|
| 78 |
-
|
| 79 |
-
|
| 80 |
-
|
| 81 |
-
|
| 82 |
-
|
| 83 |
-
|
| 84 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 85 |
{%- set reasoning_content = '' %}
|
| 86 |
-
{%-
|
| 87 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 88 |
{%- else %}
|
| 89 |
-
{%-
|
| 90 |
-
|
| 91 |
-
{%- set
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 92 |
{%- endif %}
|
| 93 |
{%- endif %}
|
| 94 |
-
{%- set reasoning_content = reasoning_content|trim %}
|
| 95 |
-
{%- if
|
| 96 |
-
{{- '<|im_start|>
|
| 97 |
{%- else %}
|
| 98 |
-
{{- '<|im_start|>
|
| 99 |
{%- endif %}
|
| 100 |
-
{%- if message.tool_calls and message.tool_calls is iterable and message.tool_calls is not mapping %}
|
| 101 |
{%- for tool_call in message.tool_calls %}
|
| 102 |
-
{%- if tool_call.function is defined %}
|
| 103 |
-
{%- set
|
| 104 |
-
{%- endif %}
|
| 105 |
-
{%- if loop.first %}
|
| 106 |
-
{%- if content|trim %}
|
| 107 |
-
{{- '\n\n' }}
|
| 108 |
-
{%- endif %}
|
| 109 |
{%- else %}
|
| 110 |
-
{
|
| 111 |
{%- endif %}
|
| 112 |
-
{%- if
|
| 113 |
-
|
| 114 |
-
{%-
|
| 115 |
-
{
|
| 116 |
-
|
| 117 |
-
{
|
| 118 |
-
|
| 119 |
-
|
| 120 |
-
{
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 121 |
{%- else %}
|
| 122 |
-
{
|
| 123 |
-
|
| 124 |
-
|
|
|
|
|
|
|
|
|
|
| 125 |
{%- else %}
|
| 126 |
-
{{- tool_call
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 127 |
{%- endif %}
|
| 128 |
-
{{- '
|
| 129 |
{%- endif %}
|
| 130 |
{%- endfor %}
|
| 131 |
{%- endif %}
|
| 132 |
{{- '<|im_end|>\n' }}
|
| 133 |
-
{%- elif message.role ==
|
| 134 |
-
{%-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 135 |
{{- '<|im_start|>user' }}
|
| 136 |
{%- endif %}
|
| 137 |
-
{
|
| 138 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 139 |
{{- '\n</tool_response>' }}
|
| 140 |
-
{%- if
|
| 141 |
-
{{- '<|im_end|>\n' }}
|
| 142 |
-
{%- elif loop.last %}
|
| 143 |
{{- '<|im_end|>\n' }}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 144 |
{%- endif %}
|
| 145 |
{%- else %}
|
| 146 |
-
{{-
|
| 147 |
{%- endif %}
|
|
|
|
| 148 |
{%- endfor %}
|
| 149 |
-
{%- if add_generation_prompt %}
|
|
|
|
| 150 |
{{- '<|im_start|>assistant\n' }}
|
| 151 |
-
{%- if
|
| 152 |
{{- '<think>\n\n</think>\n\n' }}
|
| 153 |
{%- else %}
|
| 154 |
{{- '<think>\n' }}
|
| 155 |
{%- endif %}
|
| 156 |
{%- endif %}
|
| 157 |
-
{%- endif %}
|
|
|
|
| 1 |
+
{%- set template_version = "qwen3.8-froggeric-v22.5.1-jack" %}
|
| 2 |
+
{%- set _tool_format = tool_call_format if tool_call_format is defined else 'xml' %}
|
| 3 |
{%- set image_count = namespace(value=0) %}
|
| 4 |
{%- set video_count = namespace(value=0) %}
|
| 5 |
+
{%- set add_vision_id = (add_vision_id in (true, 'true', 'True', 1, '1', 'on')) if add_vision_id is defined else false %}
|
| 6 |
+
{%- set enable_thinking = (enable_thinking not in (false, 'false', 'False', 0, '0', 'off', 'none')) if enable_thinking is defined else true %}
|
| 7 |
+
{%- set auto_disable_thinking_with_tools = (auto_disable_thinking_with_tools in (true, 'true', 'True', 1, '1', 'on')) if auto_disable_thinking_with_tools is defined else false %}
|
| 8 |
+
{%- if preserve_reasoning is defined and preserve_reasoning is not none %}
|
| 9 |
+
{%- set _preserve_thinking = (preserve_reasoning not in (false, 'false', 'False', 0, '0', 'off', 'none')) %}
|
| 10 |
+
{%- elif preserve_thinking is defined and preserve_thinking is not none %}
|
| 11 |
+
{%- set _preserve_thinking = (preserve_thinking not in (false, 'false', 'False', 0, '0', 'off', 'none')) %}
|
| 12 |
+
{%- else %}
|
| 13 |
+
{%- set _preserve_thinking = true %}
|
| 14 |
+
{%- endif %}
|
| 15 |
+
{%- set max_tool_arg_chars = (max_tool_arg_chars | int) if (max_tool_arg_chars is defined and max_tool_arg_chars is not none) else 0 %}
|
| 16 |
+
{%- set max_tool_response_chars = (max_tool_response_chars | int) if (max_tool_response_chars is defined and max_tool_response_chars is not none) else 0 %}
|
| 17 |
+
{%- set _has_tools = (tools is defined and tools and tools is iterable and tools is not mapping) %}
|
| 18 |
+
{%- set _effort_raw = (reasoning_effort | string | lower) if reasoning_effort is defined and reasoning_effort is not none else 'medium' %}
|
| 19 |
+
{%- set _initial_thinking = enable_thinking %}
|
| 20 |
+
{%- set _initial_effort = 'medium' %}
|
| 21 |
+
{%- if _effort_raw in ('none', 'off') %}
|
| 22 |
+
{%- set _initial_thinking = false %}
|
| 23 |
+
{%- set _initial_effort = 'medium' %}
|
| 24 |
+
{%- elif _effort_raw in ('minimal', 'low') %}
|
| 25 |
+
{%- set _initial_effort = 'low' %}
|
| 26 |
+
{%- elif _effort_raw in ('high', 'xhigh', 'max', 'ultracode', 'extreme', 'deep', 'long') %}
|
| 27 |
+
{%- set _initial_effort = 'xhigh' %}
|
| 28 |
+
{%- else %}
|
| 29 |
+
{%- set _initial_effort = 'medium' %}
|
| 30 |
+
{%- endif %}
|
| 31 |
+
{%- set ns_state = namespace(thinking=_initial_thinking, effort=_initial_effort) %}
|
| 32 |
+
{%- if auto_disable_thinking_with_tools and _has_tools %}
|
| 33 |
+
{%- set ns_state.thinking = false %}
|
| 34 |
+
{%- endif %}
|
| 35 |
+
{%- for msg in messages %}
|
| 36 |
+
{%- if msg.role == 'system' or msg.role == 'developer' or msg.role == 'user' %}
|
| 37 |
+
{%- if msg.content is string %}
|
| 38 |
+
{%- if '<|think_off|>' in msg.content %}
|
| 39 |
+
{%- set ns_state.thinking = false %}
|
| 40 |
+
{%- elif '<|think_on|>' in msg.content %}
|
| 41 |
+
{%- set ns_state.thinking = true %}
|
| 42 |
+
{%- elif '<|think_xhigh|>' in msg.content or '<|think_high|>' in msg.content or '<|think_ultracode|>' in msg.content or '<|think_extreme|>' in msg.content or '<|think_max|>' in msg.content or '<|think_deep|>' in msg.content or '<|think_long|>' in msg.content %}
|
| 43 |
+
{%- set ns_state.thinking = true %}
|
| 44 |
+
{%- set ns_state.effort = 'xhigh' %}
|
| 45 |
+
{%- elif '<|think_low|>' in msg.content or '<|think_minimal|>' in msg.content %}
|
| 46 |
+
{%- set ns_state.thinking = true %}
|
| 47 |
+
{%- set ns_state.effort = 'low' %}
|
| 48 |
+
{%- elif '<|think_medium|>' in msg.content %}
|
| 49 |
+
{%- set ns_state.thinking = true %}
|
| 50 |
+
{%- set ns_state.effort = 'medium' %}
|
| 51 |
+
{%- endif %}
|
| 52 |
+
{%- elif msg.content is iterable and msg.content is not mapping %}
|
| 53 |
+
{%- for item in msg.content %}
|
| 54 |
+
{%- if item is string %}
|
| 55 |
+
{%- set _item_text = item %}
|
| 56 |
+
{%- elif item is mapping and 'text' in item and item.text is string %}
|
| 57 |
+
{%- set _item_text = item.text %}
|
| 58 |
+
{%- elif item is mapping and 'content' in item and item.content is string %}
|
| 59 |
+
{%- set _item_text = item.content %}
|
| 60 |
+
{%- else %}
|
| 61 |
+
{%- set _item_text = '' %}
|
| 62 |
+
{%- endif %}
|
| 63 |
+
{%- if _item_text %}
|
| 64 |
+
{%- if '<|think_off|>' in _item_text %}
|
| 65 |
+
{%- set ns_state.thinking = false %}
|
| 66 |
+
{%- elif '<|think_on|>' in _item_text %}
|
| 67 |
+
{%- set ns_state.thinking = true %}
|
| 68 |
+
{%- elif '<|think_xhigh|>' in _item_text or '<|think_high|>' in _item_text or '<|think_ultracode|>' in _item_text or '<|think_extreme|>' in _item_text or '<|think_max|>' in _item_text or '<|think_deep|>' in _item_text or '<|think_long|>' in _item_text %}
|
| 69 |
+
{%- set ns_state.thinking = true %}
|
| 70 |
+
{%- set ns_state.effort = 'xhigh' %}
|
| 71 |
+
{%- elif '<|think_low|>' in _item_text or '<|think_minimal|>' in _item_text %}
|
| 72 |
+
{%- set ns_state.thinking = true %}
|
| 73 |
+
{%- set ns_state.effort = 'low' %}
|
| 74 |
+
{%- elif '<|think_medium|>' in _item_text %}
|
| 75 |
+
{%- set ns_state.thinking = true %}
|
| 76 |
+
{%- set ns_state.effort = 'medium' %}
|
| 77 |
+
{%- endif %}
|
| 78 |
+
{%- endif %}
|
| 79 |
+
{%- endfor %}
|
| 80 |
+
{%- endif %}
|
| 81 |
+
{%- endif %}
|
| 82 |
+
{%- endfor %}
|
| 83 |
+
{%- set reasoning_instructions = '' %}
|
| 84 |
+
{%- if ns_state.thinking %}
|
| 85 |
+
{%- if ns_state.effort == 'xhigh' %}
|
| 86 |
+
{%- set reasoning_instructions = 'Reasoning effort is set to xhigh. Please think carefully through the task, validate key assumptions, consider plausible alternatives, and prioritize correctness, consistency, and clarity in the final answer.' %}
|
| 87 |
+
{%- elif ns_state.effort == 'low' %}
|
| 88 |
+
{%- set reasoning_instructions = 'Reasoning effort is set to low. Keep your thinking brief and focused, moving directly to the conclusion without unnecessary elaboration.' %}
|
| 89 |
+
{%- endif %}
|
| 90 |
+
{%- endif %}
|
| 91 |
{%- macro render_content(content, do_vision_count, is_system_content=false) %}
|
| 92 |
{%- if content is string %}
|
| 93 |
{{- content }}
|
| 94 |
{%- elif content is iterable and content is not mapping %}
|
| 95 |
{%- for item in content %}
|
| 96 |
+
{%- if item is mapping %}
|
| 97 |
+
{%- if item.type == 'image' or 'image' in item or 'image_url' in item %}
|
| 98 |
+
{%- if is_system_content %}
|
| 99 |
+
{{- raise_exception('System message cannot contain images.') }}
|
| 100 |
+
{%- endif %}
|
| 101 |
+
{%- if do_vision_count %}
|
| 102 |
+
{%- set image_count.value = image_count.value + 1 %}
|
| 103 |
+
{%- endif %}
|
| 104 |
+
{%- if add_vision_id %}
|
| 105 |
+
{{- 'Picture ' ~ image_count.value ~ ': ' }}
|
| 106 |
+
{%- endif %}
|
| 107 |
+
{{- '<|vision_start|><|image_pad|><|vision_end|>' }}
|
| 108 |
+
{%- elif item.type == 'video' or 'video' in item %}
|
| 109 |
+
{%- if is_system_content %}
|
| 110 |
+
{{- raise_exception('System message cannot contain videos.') }}
|
| 111 |
+
{%- endif %}
|
| 112 |
+
{%- if do_vision_count %}
|
| 113 |
+
{%- set video_count.value = video_count.value + 1 %}
|
| 114 |
+
{%- endif %}
|
| 115 |
+
{%- if add_vision_id %}
|
| 116 |
+
{{- 'Video ' ~ video_count.value ~ ': ' }}
|
| 117 |
+
{%- endif %}
|
| 118 |
+
{{- '<|vision_start|><|video_pad|><|vision_end|>' }}
|
| 119 |
+
{%- elif 'text' in item %}
|
| 120 |
+
{{- (item.text | string) if item.text is not none else '' }}
|
| 121 |
+
{%- elif 'content' in item and item.content is string %}
|
| 122 |
+
{{- item.content }}
|
| 123 |
+
{%- else %}
|
| 124 |
+
{{- item | tojson }}
|
| 125 |
{%- endif %}
|
|
|
|
|
|
|
|
|
|
| 126 |
{%- else %}
|
| 127 |
+
{{- item | string }}
|
| 128 |
{%- endif %}
|
| 129 |
{%- endfor %}
|
| 130 |
{%- elif content is none or content is undefined %}
|
|
|
|
| 133 |
{{- raise_exception('Unexpected content type.') }}
|
| 134 |
{%- endif %}
|
| 135 |
{%- endmacro %}
|
| 136 |
+
{%- if not messages %}
|
| 137 |
+
{{- raise_exception('No messages provided.') }}
|
| 138 |
+
{%- endif %}
|
| 139 |
+
{%- set head = namespace(count=0, seen_non_system=false) %}
|
| 140 |
+
{%- for message in messages %}
|
| 141 |
+
{%- set _is_sys = (message.role == 'system' or message.role == 'developer') %}
|
| 142 |
+
{%- if _is_sys and not head.seen_non_system %}
|
| 143 |
+
{%- set head.count = head.count + 1 %}
|
| 144 |
+
{%- else %}
|
| 145 |
+
{%- set head.seen_non_system = true %}
|
| 146 |
+
{%- endif %}
|
| 147 |
+
{%- endfor %}
|
| 148 |
+
{%- set sys_state = namespace(content='') %}
|
| 149 |
+
{%- for message in messages[:head.count] %}
|
| 150 |
+
{%- set _part = render_content(message.content, false, true) | trim %}
|
| 151 |
+
{%- if '<|think_off|>' in _part %}{%- set _part = _part.split('<|think_off|>') | join('') | trim %}{%- endif %}
|
| 152 |
+
{%- if '<|think_on|>' in _part %}{%- set _part = _part.split('<|think_on|>') | join('') | trim %}{%- endif %}
|
| 153 |
+
{%- if '<|think_xhigh|>' in _part %}{%- set _part = _part.split('<|think_xhigh|>') | join('') | trim %}{%- endif %}
|
| 154 |
+
{%- if '<|think_high|>' in _part %}{%- set _part = _part.split('<|think_high|>') | join('') | trim %}{%- endif %}
|
| 155 |
+
{%- if '<|think_ultracode|>' in _part %}{%- set _part = _part.split('<|think_ultracode|>') | join('') | trim %}{%- endif %}
|
| 156 |
+
{%- if '<|think_extreme|>' in _part %}{%- set _part = _part.split('<|think_extreme|>') | join('') | trim %}{%- endif %}
|
| 157 |
+
{%- if '<|think_max|>' in _part %}{%- set _part = _part.split('<|think_max|>') | join('') | trim %}{%- endif %}
|
| 158 |
+
{%- if '<|think_deep|>' in _part %}{%- set _part = _part.split('<|think_deep|>') | join('') | trim %}{%- endif %}
|
| 159 |
+
{%- if '<|think_long|>' in _part %}{%- set _part = _part.split('<|think_long|>') | join('') | trim %}{%- endif %}
|
| 160 |
+
{%- if '<|think_medium|>' in _part %}{%- set _part = _part.split('<|think_medium|>') | join('') | trim %}{%- endif %}
|
| 161 |
+
{%- if '<|think_low|>' in _part %}{%- set _part = _part.split('<|think_low|>') | join('') | trim %}{%- endif %}
|
| 162 |
+
{%- if '<|think_minimal|>' in _part %}{%- set _part = _part.split('<|think_minimal|>') | join('') | trim %}{%- endif %}
|
| 163 |
+
{%- if _part %}
|
| 164 |
+
{%- if sys_state.content %}
|
| 165 |
+
{%- set sys_state.content = sys_state.content ~ '\n\n' ~ _part %}
|
| 166 |
+
{%- else %}
|
| 167 |
+
{%- set sys_state.content = _part %}
|
| 168 |
+
{%- endif %}
|
| 169 |
+
{%- endif %}
|
| 170 |
+
{%- endfor %}
|
| 171 |
+
{%- set _sc = sys_state.content %}
|
| 172 |
+
{%- set _msgs = messages[head.count:] %}
|
| 173 |
+
{%- set _terse_on = (terse in (true, 'true', 'True', 1, '1', 'on')) if terse is defined else false %}
|
| 174 |
+
{%- if _terse_on %}
|
| 175 |
+
{%- if ns_state.thinking %}
|
| 176 |
+
{%- set _terse_lead = 'Answer directly, after thinking. Lead with the answer, then only what it needs to be correct and usable.' %}
|
| 177 |
+
{%- else %}
|
| 178 |
+
{%- set _terse_lead = 'Answer directly and concisely. Give the answer with only what it needs to be correct and usable.' %}
|
| 179 |
+
{%- endif %}
|
| 180 |
+
{%- set _terse_core %}
|
| 181 |
+
Never: open with preamble or pleasantries; restate the question; add filler transitions; hedge with niceties; or repeat a point you've already made.
|
| 182 |
+
Always: keep essential steps, caveats, uncertainties, and specifics — never drop correctness or a needed warning for brevity. Keep the final answer lean. Use the least structure that conveys it (plain prose when short; lists or code only when they earn their place). If genuinely uncertain, say so and explain why — never omit uncertainty for the sake of brevity.
|
| 183 |
+
If a user request is genuinely ambiguous, ask a sharp question, don't guess.
|
| 184 |
+
{%- endset %}
|
| 185 |
+
{%- set _terse = _terse_lead ~ '\n' ~ (_terse_core | trim) %}
|
| 186 |
+
{%- if not _sc %}
|
| 187 |
+
{%- set _sc = _terse | trim %}
|
| 188 |
+
{%- else %}
|
| 189 |
+
{%- set _sc = (_sc | trim) ~ '\n\n' ~ (_terse | trim) %}
|
| 190 |
+
{%- endif %}
|
| 191 |
+
{%- endif %}
|
| 192 |
+
{%- if _has_tools %}
|
| 193 |
{{- '<|im_start|>system\n' }}
|
| 194 |
+
{%- if reasoning_instructions %}
|
| 195 |
+
{{- reasoning_instructions + '\n\n' }}
|
| 196 |
+
{%- endif %}
|
| 197 |
+
{{- '# Tools\n\nYou have access to the following functions:\n\n<tools>' }}
|
| 198 |
{%- for tool in tools %}
|
| 199 |
+
{{- '\n' }}
|
| 200 |
{{- tool | tojson }}
|
| 201 |
{%- endfor %}
|
| 202 |
+
{{- '\n</tools>' }}
|
| 203 |
+
{%- if _tool_format == 'json' %}
|
| 204 |
+
{{- '\n\nIf you choose to call a function ONLY reply in the following format with NO suffix:\n\n' }}{%- if ns_state.thinking %}{{- '<think>\nBrief explanation of tool call\n</think>\n' }}{%- endif %}{{- '<tool_call>\n{"name": "example_function_name", "arguments": {"example_parameter_1": "value_1", "example_parameter_2": "This is the value for the second parameter"}}\n</tool_call>\n\n<IMPORTANT>\nReminder:\n' }}{%- if ns_state.thinking %}{{- '- You can use the <think></think> block to plan your next tool call OR to synthesize data and formulate your final response to the user.\n- ALL explanation and reasoning MUST be placed strictly inside the <think></think> block.\n' }}{%- endif %}{{- '- Function calls MUST follow the specified format: a single JSON object with "name" and "arguments" keys inside <tool_call></tool_call> XML tags.\n- If you choose to call a tool, you MUST output the <tool_call> block IMMEDIATELY' }}{%- if ns_state.thinking %}{{- ' after thinking' }}{%- endif %}{{- ', with NO conversational text before it.\n- The <tool_call> tag MUST be at the very beginning of a new line, with NO spaces or indentation before it.\n- To call multiple functions, output a separate, completely closed <tool_call></tool_call> block for EACH function. Do NOT nest <tool_call> blocks.\n- If you have all necessary data, provide your final answer directly to the user without any tool call.\n</IMPORTANT>' }}
|
| 205 |
+
{%- else %}
|
| 206 |
+
{{- '\n\nIf you choose to call a function ONLY reply in the following format with NO suffix:\n\n' }}{%- if ns_state.thinking %}{{- '<think>\nBrief explanation of tool call\n</think>\n' }}{%- endif %}{{- '<tool_call>\n<function=example_function_name>\n<parameter=example_parameter_1>\nvalue_1\n</parameter>\n<parameter=example_parameter_2>\nThis is the value for the second parameter\nthat can span\nmultiple lines\n</parameter>\n</function>\n</tool_call>\n\n<IMPORTANT>\nReminder:\n' }}{%- if ns_state.thinking %}{{- '- You can use the <think></think> block to plan your next tool call OR to synthesize data and formulate your final response to the user.\n- ALL explanation and reasoning MUST be placed strictly inside the <think></think> block.\n' }}{%- endif %}{{- '- Function calls MUST follow the specified format: an inner <function=...></function> block must be nested within <tool_call></tool_call> XML tags.\n- If you choose to call a tool, you MUST output the <tool_call> block IMMEDIATELY' }}{%- if ns_state.thinking %}{{- ' after thinking' }}{%- endif %}{{- ', with NO conversational text before it.\n- The <tool_call> and <function> tags MUST be at the very beginning of a new line, with NO spaces or indentation before them.\n- To call multiple functions, output a separate, completely closed <tool_call></tool_call> block for EACH function. Do NOT nest <tool_call> blocks.\n- If you have all necessary data, provide your final answer directly to the user without any tool call.\n</IMPORTANT>' }}
|
| 207 |
+
{%- endif %}
|
| 208 |
+
{%- if _sc %}
|
| 209 |
+
{{- '\n\n' + _sc }}
|
| 210 |
{%- endif %}
|
| 211 |
{{- '<|im_end|>\n' }}
|
| 212 |
{%- else %}
|
| 213 |
+
{%- if _sc %}
|
| 214 |
+
{{- '<|im_start|>system\n' + (reasoning_instructions + '\n\n' if reasoning_instructions else '') + _sc + '<|im_end|>\n' }}
|
| 215 |
+
{%- elif reasoning_instructions %}
|
| 216 |
+
{{- '<|im_start|>system\n' + reasoning_instructions + '<|im_end|>\n' }}
|
| 217 |
{%- endif %}
|
| 218 |
{%- endif %}
|
| 219 |
+
{%- set _last_idx = _msgs | length - 1 %}
|
| 220 |
+
{%- set ns = namespace(multi_step_tool=true, last_query_index=_last_idx) %}
|
| 221 |
+
{%- for message in _msgs[::-1] %}
|
| 222 |
+
{%- set index = (_msgs | length - 1) - loop.index0 %}
|
| 223 |
+
{%- if ns.multi_step_tool and message.role == 'user' %}
|
| 224 |
+
{%- set _rc = render_content(message.content, false) | trim %}
|
| 225 |
+
{%- if not (_rc.startswith('<tool_response>') and _rc.endswith('</tool_response>')) %}
|
| 226 |
{%- set ns.multi_step_tool = false %}
|
| 227 |
{%- set ns.last_query_index = index %}
|
| 228 |
{%- endif %}
|
| 229 |
{%- endif %}
|
| 230 |
{%- endfor %}
|
| 231 |
+
{%- if ns.multi_step_tool %}
|
| 232 |
+
{%- if _last_idx > 50 %}
|
| 233 |
+
{%- set ns.last_query_index = _last_idx %}
|
| 234 |
+
{%- else %}
|
| 235 |
+
{%- set ns.last_query_index = 0 %}
|
| 236 |
+
{%- endif %}
|
| 237 |
+
{%- endif %}
|
| 238 |
+
{%- set ns2 = namespace(prev_role='', consecutive_failures=0) %}
|
| 239 |
+
{%- for message in _msgs %}
|
| 240 |
+
{%- set is_system = (message.role == "system" or message.role == "developer") %}
|
| 241 |
+
{%- set content = render_content(message.content, true, is_system) | trim %}
|
| 242 |
+
{%- if is_system or message.role == 'user' %}
|
| 243 |
+
{%- if '<|think_off|>' in content %}{%- set content = content.split('<|think_off|>') | join('') | trim %}{%- endif %}
|
| 244 |
+
{%- if '<|think_on|>' in content %}{%- set content = content.split('<|think_on|>') | join('') | trim %}{%- endif %}
|
| 245 |
+
{%- if '<|think_xhigh|>' in content %}{%- set content = content.split('<|think_xhigh|>') | join('') | trim %}{%- endif %}
|
| 246 |
+
{%- if '<|think_high|>' in content %}{%- set content = content.split('<|think_high|>') | join('') | trim %}{%- endif %}
|
| 247 |
+
{%- if '<|think_ultracode|>' in content %}{%- set content = content.split('<|think_ultracode|>') | join('') | trim %}{%- endif %}
|
| 248 |
+
{%- if '<|think_extreme|>' in content %}{%- set content = content.split('<|think_extreme|>') | join('') | trim %}{%- endif %}
|
| 249 |
+
{%- if '<|think_max|>' in content %}{%- set content = content.split('<|think_max|>') | join('') | trim %}{%- endif %}
|
| 250 |
+
{%- if '<|think_deep|>' in content %}{%- set content = content.split('<|think_deep|>') | join('') | trim %}{%- endif %}
|
| 251 |
+
{%- if '<|think_long|>' in content %}{%- set content = content.split('<|think_long|>') | join('') | trim %}{%- endif %}
|
| 252 |
+
{%- if '<|think_medium|>' in content %}{%- set content = content.split('<|think_medium|>') | join('') | trim %}{%- endif %}
|
| 253 |
+
{%- if '<|think_low|>' in content %}{%- set content = content.split('<|think_low|>') | join('') | trim %}{%- endif %}
|
| 254 |
+
{%- if '<|think_minimal|>' in content %}{%- set content = content.split('<|think_minimal|>') | join('') | trim %}{%- endif %}
|
| 255 |
+
{%- endif %}
|
| 256 |
+
{%- if is_system %}
|
| 257 |
+
{{- '<|im_start|>system\n' + content + '<|im_end|>\n' }}
|
| 258 |
+
{%- elif message.role == 'user' %}
|
| 259 |
+
{%- set ns2.consecutive_failures = 0 %}
|
| 260 |
+
{{- '<|im_start|>user\n' + content + '<|im_end|>\n' }}
|
| 261 |
+
{%- elif message.role == 'assistant' %}
|
| 262 |
{%- set reasoning_content = '' %}
|
| 263 |
+
{%- set _explicit_reasoning = '' %}
|
| 264 |
+
{%- if message.reasoning_content is defined and message.reasoning_content is not none %}
|
| 265 |
+
{%- if message.reasoning_content is string %}
|
| 266 |
+
{%- set _explicit_reasoning = message.reasoning_content %}
|
| 267 |
+
{%- elif message.reasoning_content is mapping and 'text' in message.reasoning_content %}
|
| 268 |
+
{%- set _explicit_reasoning = message.reasoning_content.text | string %}
|
| 269 |
+
{%- else %}
|
| 270 |
+
{%- set _explicit_reasoning = message.reasoning_content | string %}
|
| 271 |
+
{%- endif %}
|
| 272 |
+
{%- elif message.thinking is defined and message.thinking is not none %}
|
| 273 |
+
{%- if message.thinking is string %}
|
| 274 |
+
{%- set _explicit_reasoning = message.thinking %}
|
| 275 |
+
{%- elif message.thinking is mapping and 'text' in message.thinking %}
|
| 276 |
+
{%- set _explicit_reasoning = message.thinking.text | string %}
|
| 277 |
+
{%- else %}
|
| 278 |
+
{%- set _explicit_reasoning = message.thinking | string %}
|
| 279 |
+
{%- endif %}
|
| 280 |
+
{%- elif message.reasoning is defined and message.reasoning is not none %}
|
| 281 |
+
{%- if message.reasoning is string %}
|
| 282 |
+
{%- set _explicit_reasoning = message.reasoning %}
|
| 283 |
+
{%- elif message.reasoning is mapping and 'text' in message.reasoning %}
|
| 284 |
+
{%- set _explicit_reasoning = message.reasoning.text | string %}
|
| 285 |
+
{%- else %}
|
| 286 |
+
{%- set _explicit_reasoning = message.reasoning | string %}
|
| 287 |
+
{%- endif %}
|
| 288 |
+
{%- endif %}
|
| 289 |
+
{%- if _explicit_reasoning %}
|
| 290 |
+
{%- set _lead_end = '' %}
|
| 291 |
+
{%- if content.startswith('<think>') and '</think>' in content %}
|
| 292 |
+
{%- set _lead_end = '</think>' %}
|
| 293 |
+
{%- elif content.startswith('<thinking>') and '</thinking>' in content %}
|
| 294 |
+
{%- set _lead_end = '</thinking>' %}
|
| 295 |
+
{%- elif content.startswith('</think>') %}
|
| 296 |
+
{%- set _lead_end = '</think>' %}
|
| 297 |
+
{%- elif content.startswith('</thinking>') %}
|
| 298 |
+
{%- set _lead_end = '</thinking>' %}
|
| 299 |
+
{%- endif %}
|
| 300 |
+
{%- if _lead_end %}
|
| 301 |
+
{%- set _parts = content.split(_lead_end) %}
|
| 302 |
+
{%- set content = (_parts[1:] | join(_lead_end)).lstrip('\n') %}
|
| 303 |
+
{%- endif %}
|
| 304 |
+
{%- set reasoning_content = _explicit_reasoning %}
|
| 305 |
{%- else %}
|
| 306 |
+
{%- set _think_end = '' %}
|
| 307 |
+
{%- if content.startswith('</think>') %}
|
| 308 |
+
{%- set _think_end = '</think>' %}
|
| 309 |
+
{%- elif content.startswith('</thinking>') %}
|
| 310 |
+
{%- set _think_end = '</thinking>' %}
|
| 311 |
+
{%- elif '\n</think>' in content %}
|
| 312 |
+
{%- set _think_end = '\n</think>' %}
|
| 313 |
+
{%- elif '\n</thinking>' in content %}
|
| 314 |
+
{%- set _think_end = '\n</thinking>' %}
|
| 315 |
+
{%- elif '\n</ think>' in content %}
|
| 316 |
+
{%- set _think_end = '\n</ think>' %}
|
| 317 |
+
{%- elif '\n</think >' in content %}
|
| 318 |
+
{%- set _think_end = '\n</think >' %}
|
| 319 |
+
{%- elif content.startswith('<think>') and '</think>' in content %}
|
| 320 |
+
{%- set _think_end = '</think>' %}
|
| 321 |
+
{%- elif content.startswith('<thinking>') and '</thinking>' in content %}
|
| 322 |
+
{%- set _think_end = '</thinking>' %}
|
| 323 |
+
{%- endif %}
|
| 324 |
+
{%- if _think_end %}
|
| 325 |
+
{%- if 'thinking' in _think_end %}
|
| 326 |
+
{%- set _think_start = '<thinking>' %}
|
| 327 |
+
{%- else %}
|
| 328 |
+
{%- set _think_start = '<think>' %}
|
| 329 |
+
{%- endif %}
|
| 330 |
+
{%- set _parts = content.split(_think_end) %}
|
| 331 |
+
{%- set reasoning_content = _parts[0].rstrip('\n') %}
|
| 332 |
+
{%- if _think_start in reasoning_content %}
|
| 333 |
+
{%- set reasoning_content = reasoning_content.split(_think_start)[-1].lstrip('\n') %}
|
| 334 |
+
{%- endif %}
|
| 335 |
+
{%- set content = (_parts[1:] | join(_think_end)).lstrip('\n') %}
|
| 336 |
{%- endif %}
|
| 337 |
{%- endif %}
|
| 338 |
+
{%- set reasoning_content = reasoning_content | trim %}
|
| 339 |
+
{%- if reasoning_content and (_preserve_thinking or loop.index0 > ns.last_query_index) %}
|
| 340 |
+
{{- '<|im_start|>assistant\n<think>\n' + reasoning_content + '\n</think>\n\n' + content }}
|
| 341 |
{%- else %}
|
| 342 |
+
{{- '<|im_start|>assistant\n' + content }}
|
| 343 |
{%- endif %}
|
| 344 |
+
{%- if message.tool_calls is defined and message.tool_calls and message.tool_calls is iterable and message.tool_calls is not mapping %}
|
| 345 |
{%- for tool_call in message.tool_calls %}
|
| 346 |
+
{%- if tool_call.function is defined and tool_call.function is not none %}
|
| 347 |
+
{%- set tc = tool_call.function %}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 348 |
{%- else %}
|
| 349 |
+
{%- set tc = tool_call %}
|
| 350 |
{%- endif %}
|
| 351 |
+
{%- set tc_name = tc.name if (tc.name is defined and tc.name is not none) else '' %}
|
| 352 |
+
{%- if _tool_format == 'json' %}
|
| 353 |
+
{%- if loop.first %}
|
| 354 |
+
{%- if content | trim %}
|
| 355 |
+
{{- '\n\n' }}
|
| 356 |
+
{%- endif %}
|
| 357 |
+
{%- else %}
|
| 358 |
+
{{- '\n' }}
|
| 359 |
+
{%- endif %}
|
| 360 |
+
{%- set _args = '{}' %}
|
| 361 |
+
{%- if tc.arguments is defined and tc.arguments is not none %}
|
| 362 |
+
{%- if tc.arguments is mapping %}
|
| 363 |
+
{%- set _args = tc.arguments | tojson %}
|
| 364 |
+
{%- elif tc.arguments is string %}
|
| 365 |
+
{%- if tc.arguments %}
|
| 366 |
+
{%- set _args = tc.arguments %}
|
| 367 |
+
{%- endif %}
|
| 368 |
+
{%- else %}
|
| 369 |
+
{%- set _args = tc.arguments | tojson %}
|
| 370 |
+
{%- endif %}
|
| 371 |
+
{%- endif %}
|
| 372 |
+
{{- '<tool_call>\n{"name": ' }}{{- tc_name | tojson }}{{- ', "arguments": ' }}{{- _args }}{{- '}\n</tool_call>' }}
|
| 373 |
{%- else %}
|
| 374 |
+
{%- if loop.first %}
|
| 375 |
+
{%- if content | trim %}
|
| 376 |
+
{{- '\n\n<tool_call>\n<function=' + tc_name + '>\n' }}
|
| 377 |
+
{%- else %}
|
| 378 |
+
{{- '<tool_call>\n<function=' + tc_name + '>\n' }}
|
| 379 |
+
{%- endif %}
|
| 380 |
{%- else %}
|
| 381 |
+
{{- '\n<tool_call>\n<function=' + tc_name + '>\n' }}
|
| 382 |
+
{%- endif %}
|
| 383 |
+
{%- if tc.arguments is defined and tc.arguments is not none %}
|
| 384 |
+
{%- if tc.arguments is mapping %}
|
| 385 |
+
{%- for args_name, args_value in tc.arguments.items() %}
|
| 386 |
+
{{- '<parameter=' + args_name + '>\n' }}
|
| 387 |
+
{%- if args_value is string %}
|
| 388 |
+
{%- set _av = args_value %}
|
| 389 |
+
{%- else %}
|
| 390 |
+
{%- set _av = args_value | tojson %}
|
| 391 |
+
{%- endif %}
|
| 392 |
+
{%- if max_tool_arg_chars > 0 and _av | length > max_tool_arg_chars %}
|
| 393 |
+
{{- _av[:max_tool_arg_chars] + '\n[TRUNCATED - original length ' ~ (_av | length | string) ~ ' chars]' }}
|
| 394 |
+
{%- else %}
|
| 395 |
+
{{- _av }}
|
| 396 |
+
{%- endif %}
|
| 397 |
+
{{- '\n</parameter>\n' }}
|
| 398 |
+
{%- endfor %}
|
| 399 |
+
{%- else %}
|
| 400 |
+
{%- if tc.arguments is string %}
|
| 401 |
+
{%- set _raw_args = tc.arguments %}
|
| 402 |
+
{%- else %}
|
| 403 |
+
{%- set _raw_args = tc.arguments | tojson %}
|
| 404 |
+
{%- endif %}
|
| 405 |
+
{%- if _raw_args %}
|
| 406 |
+
{%- if max_tool_arg_chars > 0 and _raw_args | length > max_tool_arg_chars %}
|
| 407 |
+
{{- _raw_args[:max_tool_arg_chars] + '\n[TRUNCATED - original length ' ~ (_raw_args | length | string) ~ ' chars]' }}
|
| 408 |
+
{%- else %}
|
| 409 |
+
{{- _raw_args }}
|
| 410 |
+
{%- endif %}
|
| 411 |
+
{%- endif %}
|
| 412 |
+
{%- endif %}
|
| 413 |
{%- endif %}
|
| 414 |
+
{{- '</function>\n</tool_call>' }}
|
| 415 |
{%- endif %}
|
| 416 |
{%- endfor %}
|
| 417 |
{%- endif %}
|
| 418 |
{{- '<|im_end|>\n' }}
|
| 419 |
+
{%- elif message.role == 'tool' %}
|
| 420 |
+
{%- set _content_lower = content | lower %}
|
| 421 |
+
{%- set _content_head = _content_lower[:120] %}
|
| 422 |
+
{%- set _is_code_or_grep = ('throw new ' in _content_lower or 'throw error' in _content_lower or 'console.error' in _content_lower or 'logger.error' in _content_lower or 'logging.error' in _content_lower or 'import ' in _content_head or 'def ' in _content_head or 'function ' in _content_head) %}
|
| 423 |
+
{%- set _exit_code_zero = ('exit code: 0' in _content_head or 'process exited with code 0' in _content_head) %}
|
| 424 |
+
{%- set _error_field_ok = ('"error": null' in _content_head or '"error":null' in _content_head or '"error": false' in _content_head or '"error":false' in _content_head or '"error": ""' in _content_head or '"error":""' in _content_head) %}
|
| 425 |
+
{%- set _strong_error = (('"error":' in _content_head and not _error_field_ok) or '"status": "error"' in _content_head or '"status":"error"' in _content_head or 'traceback (most recent call last):' in _content_head or 'command not found' in _content_head or 'invalid syntax' in _content_head or 'fatal:' in _content_head or '404 not found' in _content_head or 'rate limit' in _content_head or 'connection refused' in _content_head or 'timed out' in _content_head or (('exit code: ' in _content_head or 'process exited with code' in _content_head) and not _exit_code_zero) or _content_head.startswith('exception:') or _content_head.startswith('failed to ')) %}
|
| 426 |
+
{%- set _weak_error = ('error:' in _content_head or 'err!' in _content_head) %}
|
| 427 |
+
{%- set _weak_suppressed = ('$ ' in _content_head or 'took ' in _content_head or content | length >= 600) %}
|
| 428 |
+
{%- if not _is_code_or_grep and (_strong_error or (_weak_error and not _weak_suppressed)) %}
|
| 429 |
+
{%- set ns2.consecutive_failures = ns2.consecutive_failures + 1 %}
|
| 430 |
+
{%- else %}
|
| 431 |
+
{%- set ns2.consecutive_failures = 0 %}
|
| 432 |
+
{%- endif %}
|
| 433 |
+
{%- if ns2.prev_role != 'tool' %}
|
| 434 |
{{- '<|im_start|>user' }}
|
| 435 |
{%- endif %}
|
| 436 |
+
{%- if max_tool_response_chars > 0 and content | length > max_tool_response_chars %}
|
| 437 |
+
{%- set content = content[:max_tool_response_chars] + '\n[TRUNCATED - original length ' ~ (content | length | string) ~ ' chars]' %}
|
| 438 |
+
{%- endif %}
|
| 439 |
+
{{- '\n<tool_response>\n' + content }}
|
| 440 |
+
{%- if ns2.consecutive_failures >= 2 %}
|
| 441 |
+
{{- '\n\n⚠️ SYSTEM WARNING: ' ~ ns2.consecutive_failures ~ ' consecutive tool errors detected. Your previous approach is incorrect. You MUST use a fundamentally different approach or corrected arguments.' }}
|
| 442 |
+
{%- elif ns2.consecutive_failures == 1 %}
|
| 443 |
+
{{- '\n\n⚠️ SYSTEM WARNING: The previous tool call returned an error. Diagnose the failure and retry with completely corrected arguments.' }}
|
| 444 |
+
{%- endif %}
|
| 445 |
{{- '\n</tool_response>' }}
|
| 446 |
+
{%- if loop.last %}
|
|
|
|
|
|
|
| 447 |
{{- '<|im_end|>\n' }}
|
| 448 |
+
{%- else %}
|
| 449 |
+
{%- set _next_role = _msgs[loop.index0 + 1].role %}
|
| 450 |
+
{%- if _next_role != 'tool' %}
|
| 451 |
+
{{- '<|im_end|>\n' }}
|
| 452 |
+
{%- endif %}
|
| 453 |
{%- endif %}
|
| 454 |
{%- else %}
|
| 455 |
+
{{- '<|im_start|>user\n[' + message.role + ']: ' + content + '<|im_end|>\n' }}
|
| 456 |
{%- endif %}
|
| 457 |
+
{%- set ns2.prev_role = message.role %}
|
| 458 |
{%- endfor %}
|
| 459 |
+
{%- set _add_gen = (add_generation_prompt in (true, 'true', 'True', 1, '1', 'on')) if add_generation_prompt is defined else false %}
|
| 460 |
+
{%- if _add_gen %}
|
| 461 |
{{- '<|im_start|>assistant\n' }}
|
| 462 |
+
{%- if not ns_state.thinking %}
|
| 463 |
{{- '<think>\n\n</think>\n\n' }}
|
| 464 |
{%- else %}
|
| 465 |
{{- '<think>\n' }}
|
| 466 |
{%- endif %}
|
| 467 |
{%- endif %}
|
|
|
tokenizer_config.json
CHANGED
|
@@ -295,5 +295,5 @@
|
|
| 295 |
"special": true
|
| 296 |
}
|
| 297 |
},
|
| 298 |
-
"chat_template": "{%- set image_count = namespace(value=0) %}\n{%- set video_count = namespace(value=0) %}\n{%- macro render_content(content, do_vision_count, is_system_content=false) %}\n {%- if content is string %}\n {{- content }}\n {%- elif content is iterable and content is not mapping %}\n {%- for item in content %}\n {%- if 'image' in item or 'image_url' in item or item.type == 'image' %}\n {%- if is_system_content %}\n {{- raise_exception('System message cannot contain images.') }}\n {%- endif %}\n {%- if do_vision_count %}\n {%- set image_count.value = image_count.value + 1 %}\n {%- endif %}\n {%- if add_vision_id %}\n {{- 'Picture ' ~ image_count.value ~ ': ' }}\n {%- endif %}\n {{- '<|vision_start|><|image_pad|><|vision_end|>' }}\n {%- elif 'video' in item or item.type == 'video' %}\n {%- if is_system_content %}\n {{- raise_exception('System message cannot contain videos.') }}\n {%- endif %}\n {%- if do_vision_count %}\n {%- set video_count.value = video_count.value + 1 %}\n {%- endif %}\n {%- if add_vision_id %}\n {{- 'Video ' ~ video_count.value ~ ': ' }}\n {%- endif %}\n {{- '<|vision_start|><|video_pad|><|vision_end|>' }}\n {%- elif 'text' in item %}\n {{- item.text }}\n {%- else %}\n {{- raise_exception('Unexpected item type in content.') }}\n {%- endif %}\n {%- endfor %}\n {%- elif content is none or content is undefined %}\n {{- '' }}\n {%- else %}\n {{- raise_exception('Unexpected content type.') }}\n {%- endif %}\n{%- endmacro %}\n{%- if messages %}\n{%- if tools and tools is iterable and tools is not mapping %}\n {{- '<|im_start|>system\\n' }}\n {{- \"# Tools\\n\\nYou have access to the following functions:\\n\\n<tools>\" }}\n {%- for tool in tools %}\n {{- \"\\n\" }}\n {{- tool | tojson }}\n {%- endfor %}\n {{- \"\\n</tools>\" }}\n {{- '\\n\\nIf you choose to call a function ONLY reply in the following format with NO suffix:\\n\\n<tool_call>\\n<function=example_function_name>\\n<parameter=example_parameter_1>\\nvalue_1\\n</parameter>\\n<parameter=example_parameter_2>\\nThis is the value for the second parameter\\nthat can span\\nmultiple lines\\n</parameter>\\n</function>\\n</tool_call>\\n\\n<IMPORTANT>\\nReminder:\\n- Function calls MUST follow the specified format: an inner <function=...></function> block must be nested within <tool_call></tool_call> XML tags\\n- Required parameters MUST be specified\\n- You may provide optional reasoning for your function call in natural language BEFORE the function call, but NOT after\\n- If there is no function call available, answer the question like normal with your current knowledge and do not tell the user about function calls\\n</IMPORTANT>' }}\n {%- if messages[0].role == 'system' %}\n {%- set content = render_content(messages[0].content, false, true)|trim %}\n {%- if content %}\n {{- '\\n\\n' + content }}\n {%- endif %}\n {%- endif %}\n {{- '<|im_end|>\\n' }}\n{%- else %}\n {%- if messages[0].role == 'system' %}\n {%- set content = render_content(messages[0].content, false, true)|trim %}\n {{- '<|im_start|>system\\n' + content + '<|im_end|>\\n' }}\n {%- endif %}\n{%- endif %}\n{%- set ns = namespace(multi_step_tool=true, last_query_index=messages|length - 1) %}\n{%- for message in messages[::-1] %}\n {%- set index = (messages|length - 1) - loop.index0 %}\n {%- if ns.multi_step_tool and message.role == \"user\" %}\n {%- set content = render_content(message.content, false)|trim %}\n {%- if not(content.startswith('<tool_response>') and content.endswith('</tool_response>')) %}\n {%- set ns.multi_step_tool = false %}\n {%- set ns.last_query_index = index %}\n {%- endif %}\n {%- endif %}\n{%- endfor %}\n{%- for message in messages %}\n {%- set content = render_content(message.content, true)|trim %}\n {%- if message.role == \"system\" %}\n {%- if not loop.first %}\n {{- raise_exception('System message must be at the beginning.') }}\n {%- endif %}\n {%- elif message.role == \"user\" %}\n {{- '<|im_start|>' + message.role + '\\n' + content + '<|im_end|>' + '\\n' }}\n {%- elif message.role == \"assistant\" %}\n {%- set reasoning_content = '' %}\n {%- if message.reasoning_content is string %}\n {%- set reasoning_content = message.reasoning_content %}\n {%- else %}\n {%- if '</think>' in content %}\n {%- set reasoning_content = content.split('</think>')[0].rstrip('\\n').split('<think>')[-1].lstrip('\\n') %}\n {%- set content = content.split('</think>')[-1].lstrip('\\n') %}\n {%- endif %}\n {%- endif %}\n {%- set reasoning_content = reasoning_content|trim %}\n {%- if (preserve_thinking is defined and preserve_thinking is true) or (loop.index0 > ns.last_query_index) %}\n {{- '<|im_start|>' + message.role + '\\n<think>\\n' + reasoning_content + '\\n</think>\\n\\n' + content }}\n {%- else %}\n {{- '<|im_start|>' + message.role + '\\n' + content }}\n {%- endif %}\n {%- if message.tool_calls and message.tool_calls is iterable and message.tool_calls is not mapping %}\n {%- for tool_call in message.tool_calls %}\n {%- if tool_call.function is defined %}\n {%- set tool_call = tool_call.function %}\n {%- endif %}\n {%- if loop.first %}\n {%- if content|trim %}\n {{- '\\n\\n' }}\n {%- endif %}\n {%- else %}\n {{- '\\n' }}\n {%- endif %}\n {%- if tool_call.arguments is mapping %}\n {{- '<tool_call>\\n<function=' + tool_call.name + '>\\n' }}\n {%- for args_name, args_value in tool_call.arguments|items %}\n {{- '<parameter=' + args_name + '>\\n' }}\n {%- set args_value = args_value | string if args_value is string else args_value | tojson | safe %}\n {{- args_value }}\n {{- '\\n</parameter>\\n' }}\n {%- endfor %}\n {{- '</function>\\n</tool_call>' }}\n {%- else %}\n {{- '<tool_call>\\n{\"name\": ' + tool_call.name|tojson + ', \"arguments\": ' }}\n {%- if tool_call.arguments is string %}\n {{- tool_call.arguments }}\n {%- else %}\n {{- tool_call.arguments | tojson | safe }}\n {%- endif %}\n {{- '}\\n</tool_call>' }}\n {%- endif %}\n {%- endfor %}\n {%- endif %}\n {{- '<|im_end|>\\n' }}\n {%- elif message.role == \"tool\" %}\n {%- if loop.previtem and loop.previtem.role != \"tool\" %}\n {{- '<|im_start|>user' }}\n {%- endif %}\n {{- '\\n<tool_response>\\n' }}\n {{- content }}\n {{- '\\n</tool_response>' }}\n {%- if not loop.last and loop.nextitem.role != \"tool\" %}\n {{- '<|im_end|>\\n' }}\n {%- elif loop.last %}\n {{- '<|im_end|>\\n' }}\n {%- endif %}\n {%- else %}\n {{- raise_exception('Unexpected message role.') }}\n {%- endif %}\n{%- endfor %}\n{%- if add_generation_prompt %}\n {{- '<|im_start|>assistant\\n' }}\n {%- if enable_thinking is defined and enable_thinking is false %}\n {{- '<think>\\n\\n</think>\\n\\n' }}\n {%- else %}\n {{- '<think>\\n' }}\n {%- endif %}\n{%- endif %}\n{%- endif %}\n"
|
| 299 |
-
}
|
|
|
|
| 295 |
"special": true
|
| 296 |
}
|
| 297 |
},
|
| 298 |
+
"chat_template": "{%- set template_version = \"qwen3.8-froggeric-v22.5.1-jack\" %}\n{%- set _tool_format = tool_call_format if tool_call_format is defined else 'xml' %}\n{%- set image_count = namespace(value=0) %}\n{%- set video_count = namespace(value=0) %}\n{%- set add_vision_id = (add_vision_id in (true, 'true', 'True', 1, '1', 'on')) if add_vision_id is defined else false %}\n{%- set enable_thinking = (enable_thinking not in (false, 'false', 'False', 0, '0', 'off', 'none')) if enable_thinking is defined else true %}\n{%- set auto_disable_thinking_with_tools = (auto_disable_thinking_with_tools in (true, 'true', 'True', 1, '1', 'on')) if auto_disable_thinking_with_tools is defined else false %}\n{%- if preserve_reasoning is defined and preserve_reasoning is not none %}\n {%- set _preserve_thinking = (preserve_reasoning not in (false, 'false', 'False', 0, '0', 'off', 'none')) %}\n{%- elif preserve_thinking is defined and preserve_thinking is not none %}\n {%- set _preserve_thinking = (preserve_thinking not in (false, 'false', 'False', 0, '0', 'off', 'none')) %}\n{%- else %}\n {%- set _preserve_thinking = true %}\n{%- endif %}\n{%- set max_tool_arg_chars = (max_tool_arg_chars | int) if (max_tool_arg_chars is defined and max_tool_arg_chars is not none) else 0 %}\n{%- set max_tool_response_chars = (max_tool_response_chars | int) if (max_tool_response_chars is defined and max_tool_response_chars is not none) else 0 %}\n{%- set _has_tools = (tools is defined and tools and tools is iterable and tools is not mapping) %}\n{%- set _effort_raw = (reasoning_effort | string | lower) if reasoning_effort is defined and reasoning_effort is not none else 'medium' %}\n{%- set _initial_thinking = enable_thinking %}\n{%- set _initial_effort = 'medium' %}\n{%- if _effort_raw in ('none', 'off') %}\n {%- set _initial_thinking = false %}\n {%- set _initial_effort = 'medium' %}\n{%- elif _effort_raw in ('minimal', 'low') %}\n {%- set _initial_effort = 'low' %}\n{%- elif _effort_raw in ('high', 'xhigh', 'max', 'ultracode', 'extreme', 'deep', 'long') %}\n {%- set _initial_effort = 'xhigh' %}\n{%- else %}\n {%- set _initial_effort = 'medium' %}\n{%- endif %}\n{%- set ns_state = namespace(thinking=_initial_thinking, effort=_initial_effort) %}\n{%- if auto_disable_thinking_with_tools and _has_tools %}\n {%- set ns_state.thinking = false %}\n{%- endif %}\n{%- for msg in messages %}\n {%- if msg.role == 'system' or msg.role == 'developer' or msg.role == 'user' %}\n {%- if msg.content is string %}\n {%- if '<|think_off|>' in msg.content %}\n {%- set ns_state.thinking = false %}\n {%- elif '<|think_on|>' in msg.content %}\n {%- set ns_state.thinking = true %}\n {%- elif '<|think_xhigh|>' in msg.content or '<|think_high|>' in msg.content or '<|think_ultracode|>' in msg.content or '<|think_extreme|>' in msg.content or '<|think_max|>' in msg.content or '<|think_deep|>' in msg.content or '<|think_long|>' in msg.content %}\n {%- set ns_state.thinking = true %}\n {%- set ns_state.effort = 'xhigh' %}\n {%- elif '<|think_low|>' in msg.content or '<|think_minimal|>' in msg.content %}\n {%- set ns_state.thinking = true %}\n {%- set ns_state.effort = 'low' %}\n {%- elif '<|think_medium|>' in msg.content %}\n {%- set ns_state.thinking = true %}\n {%- set ns_state.effort = 'medium' %}\n {%- endif %}\n {%- elif msg.content is iterable and msg.content is not mapping %}\n {%- for item in msg.content %}\n {%- if item is string %}\n {%- set _item_text = item %}\n {%- elif item is mapping and 'text' in item and item.text is string %}\n {%- set _item_text = item.text %}\n {%- elif item is mapping and 'content' in item and item.content is string %}\n {%- set _item_text = item.content %}\n {%- else %}\n {%- set _item_text = '' %}\n {%- endif %}\n {%- if _item_text %}\n {%- if '<|think_off|>' in _item_text %}\n {%- set ns_state.thinking = false %}\n {%- elif '<|think_on|>' in _item_text %}\n {%- set ns_state.thinking = true %}\n {%- elif '<|think_xhigh|>' in _item_text or '<|think_high|>' in _item_text or '<|think_ultracode|>' in _item_text or '<|think_extreme|>' in _item_text or '<|think_max|>' in _item_text or '<|think_deep|>' in _item_text or '<|think_long|>' in _item_text %}\n {%- set ns_state.thinking = true %}\n {%- set ns_state.effort = 'xhigh' %}\n {%- elif '<|think_low|>' in _item_text or '<|think_minimal|>' in _item_text %}\n {%- set ns_state.thinking = true %}\n {%- set ns_state.effort = 'low' %}\n {%- elif '<|think_medium|>' in _item_text %}\n {%- set ns_state.thinking = true %}\n {%- set ns_state.effort = 'medium' %}\n {%- endif %}\n {%- endif %}\n {%- endfor %}\n {%- endif %}\n {%- endif %}\n{%- endfor %}\n{%- set reasoning_instructions = '' %}\n{%- if ns_state.thinking %}\n {%- if ns_state.effort == 'xhigh' %}\n {%- set reasoning_instructions = 'Reasoning effort is set to xhigh. Please think carefully through the task, validate key assumptions, consider plausible alternatives, and prioritize correctness, consistency, and clarity in the final answer.' %}\n {%- elif ns_state.effort == 'low' %}\n {%- set reasoning_instructions = 'Reasoning effort is set to low. Keep your thinking brief and focused, moving directly to the conclusion without unnecessary elaboration.' %}\n {%- endif %}\n{%- endif %}\n{%- macro render_content(content, do_vision_count, is_system_content=false) %}\n {%- if content is string %}\n {{- content }}\n {%- elif content is iterable and content is not mapping %}\n {%- for item in content %}\n {%- if item is mapping %}\n {%- if item.type == 'image' or 'image' in item or 'image_url' in item %}\n {%- if is_system_content %}\n {{- raise_exception('System message cannot contain images.') }}\n {%- endif %}\n {%- if do_vision_count %}\n {%- set image_count.value = image_count.value + 1 %}\n {%- endif %}\n {%- if add_vision_id %}\n {{- 'Picture ' ~ image_count.value ~ ': ' }}\n {%- endif %}\n {{- '<|vision_start|><|image_pad|><|vision_end|>' }}\n {%- elif item.type == 'video' or 'video' in item %}\n {%- if is_system_content %}\n {{- raise_exception('System message cannot contain videos.') }}\n {%- endif %}\n {%- if do_vision_count %}\n {%- set video_count.value = video_count.value + 1 %}\n {%- endif %}\n {%- if add_vision_id %}\n {{- 'Video ' ~ video_count.value ~ ': ' }}\n {%- endif %}\n {{- '<|vision_start|><|video_pad|><|vision_end|>' }}\n {%- elif 'text' in item %}\n {{- (item.text | string) if item.text is not none else '' }}\n {%- elif 'content' in item and item.content is string %}\n {{- item.content }}\n {%- else %}\n {{- item | tojson }}\n {%- endif %}\n {%- else %}\n {{- item | string }}\n {%- endif %}\n {%- endfor %}\n {%- elif content is none or content is undefined %}\n {{- '' }}\n {%- else %}\n {{- raise_exception('Unexpected content type.') }}\n {%- endif %}\n{%- endmacro %}\n{%- if not messages %}\n {{- raise_exception('No messages provided.') }}\n{%- endif %}\n{%- set head = namespace(count=0, seen_non_system=false) %}\n{%- for message in messages %}\n {%- set _is_sys = (message.role == 'system' or message.role == 'developer') %}\n {%- if _is_sys and not head.seen_non_system %}\n {%- set head.count = head.count + 1 %}\n {%- else %}\n {%- set head.seen_non_system = true %}\n {%- endif %}\n{%- endfor %}\n{%- set sys_state = namespace(content='') %}\n{%- for message in messages[:head.count] %}\n {%- set _part = render_content(message.content, false, true) | trim %}\n {%- if '<|think_off|>' in _part %}{%- set _part = _part.split('<|think_off|>') | join('') | trim %}{%- endif %}\n {%- if '<|think_on|>' in _part %}{%- set _part = _part.split('<|think_on|>') | join('') | trim %}{%- endif %}\n {%- if '<|think_xhigh|>' in _part %}{%- set _part = _part.split('<|think_xhigh|>') | join('') | trim %}{%- endif %}\n {%- if '<|think_high|>' in _part %}{%- set _part = _part.split('<|think_high|>') | join('') | trim %}{%- endif %}\n {%- if '<|think_ultracode|>' in _part %}{%- set _part = _part.split('<|think_ultracode|>') | join('') | trim %}{%- endif %}\n {%- if '<|think_extreme|>' in _part %}{%- set _part = _part.split('<|think_extreme|>') | join('') | trim %}{%- endif %}\n {%- if '<|think_max|>' in _part %}{%- set _part = _part.split('<|think_max|>') | join('') | trim %}{%- endif %}\n {%- if '<|think_deep|>' in _part %}{%- set _part = _part.split('<|think_deep|>') | join('') | trim %}{%- endif %}\n {%- if '<|think_long|>' in _part %}{%- set _part = _part.split('<|think_long|>') | join('') | trim %}{%- endif %}\n {%- if '<|think_medium|>' in _part %}{%- set _part = _part.split('<|think_medium|>') | join('') | trim %}{%- endif %}\n {%- if '<|think_low|>' in _part %}{%- set _part = _part.split('<|think_low|>') | join('') | trim %}{%- endif %}\n {%- if '<|think_minimal|>' in _part %}{%- set _part = _part.split('<|think_minimal|>') | join('') | trim %}{%- endif %}\n {%- if _part %}\n {%- if sys_state.content %}\n {%- set sys_state.content = sys_state.content ~ '\\n\\n' ~ _part %}\n {%- else %}\n {%- set sys_state.content = _part %}\n {%- endif %}\n {%- endif %}\n{%- endfor %}\n{%- set _sc = sys_state.content %}\n{%- set _msgs = messages[head.count:] %}\n{%- set _terse_on = (terse in (true, 'true', 'True', 1, '1', 'on')) if terse is defined else false %}\n{%- if _terse_on %}\n {%- if ns_state.thinking %}\n {%- set _terse_lead = 'Answer directly, after thinking. Lead with the answer, then only what it needs to be correct and usable.' %}\n {%- else %}\n {%- set _terse_lead = 'Answer directly and concisely. Give the answer with only what it needs to be correct and usable.' %}\n {%- endif %}\n {%- set _terse_core %}\nNever: open with preamble or pleasantries; restate the question; add filler transitions; hedge with niceties; or repeat a point you've already made.\nAlways: keep essential steps, caveats, uncertainties, and specifics — never drop correctness or a needed warning for brevity. Keep the final answer lean. Use the least structure that conveys it (plain prose when short; lists or code only when they earn their place). If genuinely uncertain, say so and explain why — never omit uncertainty for the sake of brevity.\nIf a user request is genuinely ambiguous, ask a sharp question, don't guess.\n {%- endset %}\n {%- set _terse = _terse_lead ~ '\\n' ~ (_terse_core | trim) %}\n {%- if not _sc %}\n {%- set _sc = _terse | trim %}\n {%- else %}\n {%- set _sc = (_sc | trim) ~ '\\n\\n' ~ (_terse | trim) %}\n {%- endif %}\n{%- endif %}\n{%- if _has_tools %}\n {{- '<|im_start|>system\\n' }}\n {%- if reasoning_instructions %}\n {{- reasoning_instructions + '\\n\\n' }}\n {%- endif %}\n {{- '# Tools\\n\\nYou have access to the following functions:\\n\\n<tools>' }}\n {%- for tool in tools %}\n {{- '\\n' }}\n {{- tool | tojson }}\n {%- endfor %}\n {{- '\\n</tools>' }}\n {%- if _tool_format == 'json' %}\n {{- '\\n\\nIf you choose to call a function ONLY reply in the following format with NO suffix:\\n\\n' }}{%- if ns_state.thinking %}{{- '<think>\\nBrief explanation of tool call\\n</think>\\n' }}{%- endif %}{{- '<tool_call>\\n{\"name\": \"example_function_name\", \"arguments\": {\"example_parameter_1\": \"value_1\", \"example_parameter_2\": \"This is the value for the second parameter\"}}\\n</tool_call>\\n\\n<IMPORTANT>\\nReminder:\\n' }}{%- if ns_state.thinking %}{{- '- You can use the <think></think> block to plan your next tool call OR to synthesize data and formulate your final response to the user.\\n- ALL explanation and reasoning MUST be placed strictly inside the <think></think> block.\\n' }}{%- endif %}{{- '- Function calls MUST follow the specified format: a single JSON object with \"name\" and \"arguments\" keys inside <tool_call></tool_call> XML tags.\\n- If you choose to call a tool, you MUST output the <tool_call> block IMMEDIATELY' }}{%- if ns_state.thinking %}{{- ' after thinking' }}{%- endif %}{{- ', with NO conversational text before it.\\n- The <tool_call> tag MUST be at the very beginning of a new line, with NO spaces or indentation before it.\\n- To call multiple functions, output a separate, completely closed <tool_call></tool_call> block for EACH function. Do NOT nest <tool_call> blocks.\\n- If you have all necessary data, provide your final answer directly to the user without any tool call.\\n</IMPORTANT>' }}\n {%- else %}\n {{- '\\n\\nIf you choose to call a function ONLY reply in the following format with NO suffix:\\n\\n' }}{%- if ns_state.thinking %}{{- '<think>\\nBrief explanation of tool call\\n</think>\\n' }}{%- endif %}{{- '<tool_call>\\n<function=example_function_name>\\n<parameter=example_parameter_1>\\nvalue_1\\n</parameter>\\n<parameter=example_parameter_2>\\nThis is the value for the second parameter\\nthat can span\\nmultiple lines\\n</parameter>\\n</function>\\n</tool_call>\\n\\n<IMPORTANT>\\nReminder:\\n' }}{%- if ns_state.thinking %}{{- '- You can use the <think></think> block to plan your next tool call OR to synthesize data and formulate your final response to the user.\\n- ALL explanation and reasoning MUST be placed strictly inside the <think></think> block.\\n' }}{%- endif %}{{- '- Function calls MUST follow the specified format: an inner <function=...></function> block must be nested within <tool_call></tool_call> XML tags.\\n- If you choose to call a tool, you MUST output the <tool_call> block IMMEDIATELY' }}{%- if ns_state.thinking %}{{- ' after thinking' }}{%- endif %}{{- ', with NO conversational text before it.\\n- The <tool_call> and <function> tags MUST be at the very beginning of a new line, with NO spaces or indentation before them.\\n- To call multiple functions, output a separate, completely closed <tool_call></tool_call> block for EACH function. Do NOT nest <tool_call> blocks.\\n- If you have all necessary data, provide your final answer directly to the user without any tool call.\\n</IMPORTANT>' }}\n {%- endif %}\n {%- if _sc %}\n {{- '\\n\\n' + _sc }}\n {%- endif %}\n {{- '<|im_end|>\\n' }}\n{%- else %}\n {%- if _sc %}\n {{- '<|im_start|>system\\n' + (reasoning_instructions + '\\n\\n' if reasoning_instructions else '') + _sc + '<|im_end|>\\n' }}\n {%- elif reasoning_instructions %}\n {{- '<|im_start|>system\\n' + reasoning_instructions + '<|im_end|>\\n' }}\n {%- endif %}\n{%- endif %}\n{%- set _last_idx = _msgs | length - 1 %}\n{%- set ns = namespace(multi_step_tool=true, last_query_index=_last_idx) %}\n{%- for message in _msgs[::-1] %}\n {%- set index = (_msgs | length - 1) - loop.index0 %}\n {%- if ns.multi_step_tool and message.role == 'user' %}\n {%- set _rc = render_content(message.content, false) | trim %}\n {%- if not (_rc.startswith('<tool_response>') and _rc.endswith('</tool_response>')) %}\n {%- set ns.multi_step_tool = false %}\n {%- set ns.last_query_index = index %}\n {%- endif %}\n {%- endif %}\n{%- endfor %}\n{%- if ns.multi_step_tool %}\n {%- if _last_idx > 50 %}\n {%- set ns.last_query_index = _last_idx %}\n {%- else %}\n {%- set ns.last_query_index = 0 %}\n {%- endif %}\n{%- endif %}\n{%- set ns2 = namespace(prev_role='', consecutive_failures=0) %}\n{%- for message in _msgs %}\n {%- set is_system = (message.role == \"system\" or message.role == \"developer\") %}\n {%- set content = render_content(message.content, true, is_system) | trim %}\n {%- if is_system or message.role == 'user' %}\n {%- if '<|think_off|>' in content %}{%- set content = content.split('<|think_off|>') | join('') | trim %}{%- endif %}\n {%- if '<|think_on|>' in content %}{%- set content = content.split('<|think_on|>') | join('') | trim %}{%- endif %}\n {%- if '<|think_xhigh|>' in content %}{%- set content = content.split('<|think_xhigh|>') | join('') | trim %}{%- endif %}\n {%- if '<|think_high|>' in content %}{%- set content = content.split('<|think_high|>') | join('') | trim %}{%- endif %}\n {%- if '<|think_ultracode|>' in content %}{%- set content = content.split('<|think_ultracode|>') | join('') | trim %}{%- endif %}\n {%- if '<|think_extreme|>' in content %}{%- set content = content.split('<|think_extreme|>') | join('') | trim %}{%- endif %}\n {%- if '<|think_max|>' in content %}{%- set content = content.split('<|think_max|>') | join('') | trim %}{%- endif %}\n {%- if '<|think_deep|>' in content %}{%- set content = content.split('<|think_deep|>') | join('') | trim %}{%- endif %}\n {%- if '<|think_long|>' in content %}{%- set content = content.split('<|think_long|>') | join('') | trim %}{%- endif %}\n {%- if '<|think_medium|>' in content %}{%- set content = content.split('<|think_medium|>') | join('') | trim %}{%- endif %}\n {%- if '<|think_low|>' in content %}{%- set content = content.split('<|think_low|>') | join('') | trim %}{%- endif %}\n {%- if '<|think_minimal|>' in content %}{%- set content = content.split('<|think_minimal|>') | join('') | trim %}{%- endif %}\n {%- endif %}\n {%- if is_system %}\n {{- '<|im_start|>system\\n' + content + '<|im_end|>\\n' }}\n {%- elif message.role == 'user' %}\n {%- set ns2.consecutive_failures = 0 %}\n {{- '<|im_start|>user\\n' + content + '<|im_end|>\\n' }}\n {%- elif message.role == 'assistant' %}\n {%- set reasoning_content = '' %}\n {%- set _explicit_reasoning = '' %}\n {%- if message.reasoning_content is defined and message.reasoning_content is not none %}\n {%- if message.reasoning_content is string %}\n {%- set _explicit_reasoning = message.reasoning_content %}\n {%- elif message.reasoning_content is mapping and 'text' in message.reasoning_content %}\n {%- set _explicit_reasoning = message.reasoning_content.text | string %}\n {%- else %}\n {%- set _explicit_reasoning = message.reasoning_content | string %}\n {%- endif %}\n {%- elif message.thinking is defined and message.thinking is not none %}\n {%- if message.thinking is string %}\n {%- set _explicit_reasoning = message.thinking %}\n {%- elif message.thinking is mapping and 'text' in message.thinking %}\n {%- set _explicit_reasoning = message.thinking.text | string %}\n {%- else %}\n {%- set _explicit_reasoning = message.thinking | string %}\n {%- endif %}\n {%- elif message.reasoning is defined and message.reasoning is not none %}\n {%- if message.reasoning is string %}\n {%- set _explicit_reasoning = message.reasoning %}\n {%- elif message.reasoning is mapping and 'text' in message.reasoning %}\n {%- set _explicit_reasoning = message.reasoning.text | string %}\n {%- else %}\n {%- set _explicit_reasoning = message.reasoning | string %}\n {%- endif %}\n {%- endif %}\n {%- if _explicit_reasoning %}\n {%- set _lead_end = '' %}\n {%- if content.startswith('<think>') and '</think>' in content %}\n {%- set _lead_end = '</think>' %}\n {%- elif content.startswith('<thinking>') and '</thinking>' in content %}\n {%- set _lead_end = '</thinking>' %}\n {%- elif content.startswith('</think>') %}\n {%- set _lead_end = '</think>' %}\n {%- elif content.startswith('</thinking>') %}\n {%- set _lead_end = '</thinking>' %}\n {%- endif %}\n {%- if _lead_end %}\n {%- set _parts = content.split(_lead_end) %}\n {%- set content = (_parts[1:] | join(_lead_end)).lstrip('\\n') %}\n {%- endif %}\n {%- set reasoning_content = _explicit_reasoning %}\n {%- else %}\n {%- set _think_end = '' %}\n {%- if content.startswith('</think>') %}\n {%- set _think_end = '</think>' %}\n {%- elif content.startswith('</thinking>') %}\n {%- set _think_end = '</thinking>' %}\n {%- elif '\\n</think>' in content %}\n {%- set _think_end = '\\n</think>' %}\n {%- elif '\\n</thinking>' in content %}\n {%- set _think_end = '\\n</thinking>' %}\n {%- elif '\\n</ think>' in content %}\n {%- set _think_end = '\\n</ think>' %}\n {%- elif '\\n</think >' in content %}\n {%- set _think_end = '\\n</think >' %}\n {%- elif content.startswith('<think>') and '</think>' in content %}\n {%- set _think_end = '</think>' %}\n {%- elif content.startswith('<thinking>') and '</thinking>' in content %}\n {%- set _think_end = '</thinking>' %}\n {%- endif %}\n {%- if _think_end %}\n {%- if 'thinking' in _think_end %}\n {%- set _think_start = '<thinking>' %}\n {%- else %}\n {%- set _think_start = '<think>' %}\n {%- endif %}\n {%- set _parts = content.split(_think_end) %}\n {%- set reasoning_content = _parts[0].rstrip('\\n') %}\n {%- if _think_start in reasoning_content %}\n {%- set reasoning_content = reasoning_content.split(_think_start)[-1].lstrip('\\n') %}\n {%- endif %}\n {%- set content = (_parts[1:] | join(_think_end)).lstrip('\\n') %}\n {%- endif %}\n {%- endif %}\n {%- set reasoning_content = reasoning_content | trim %}\n {%- if reasoning_content and (_preserve_thinking or loop.index0 > ns.last_query_index) %}\n {{- '<|im_start|>assistant\\n<think>\\n' + reasoning_content + '\\n</think>\\n\\n' + content }}\n {%- else %}\n {{- '<|im_start|>assistant\\n' + content }}\n {%- endif %}\n {%- if message.tool_calls is defined and message.tool_calls and message.tool_calls is iterable and message.tool_calls is not mapping %}\n {%- for tool_call in message.tool_calls %}\n {%- if tool_call.function is defined and tool_call.function is not none %}\n {%- set tc = tool_call.function %}\n {%- else %}\n {%- set tc = tool_call %}\n {%- endif %}\n {%- set tc_name = tc.name if (tc.name is defined and tc.name is not none) else '' %}\n {%- if _tool_format == 'json' %}\n {%- if loop.first %}\n {%- if content | trim %}\n {{- '\\n\\n' }}\n {%- endif %}\n {%- else %}\n {{- '\\n' }}\n {%- endif %}\n {%- set _args = '{}' %}\n {%- if tc.arguments is defined and tc.arguments is not none %}\n {%- if tc.arguments is mapping %}\n {%- set _args = tc.arguments | tojson %}\n {%- elif tc.arguments is string %}\n {%- if tc.arguments %}\n {%- set _args = tc.arguments %}\n {%- endif %}\n {%- else %}\n {%- set _args = tc.arguments | tojson %}\n {%- endif %}\n {%- endif %}\n {{- '<tool_call>\\n{\"name\": ' }}{{- tc_name | tojson }}{{- ', \"arguments\": ' }}{{- _args }}{{- '}\\n</tool_call>' }}\n {%- else %}\n {%- if loop.first %}\n {%- if content | trim %}\n {{- '\\n\\n<tool_call>\\n<function=' + tc_name + '>\\n' }}\n {%- else %}\n {{- '<tool_call>\\n<function=' + tc_name + '>\\n' }}\n {%- endif %}\n {%- else %}\n {{- '\\n<tool_call>\\n<function=' + tc_name + '>\\n' }}\n {%- endif %}\n {%- if tc.arguments is defined and tc.arguments is not none %}\n {%- if tc.arguments is mapping %}\n {%- for args_name, args_value in tc.arguments.items() %}\n {{- '<parameter=' + args_name + '>\\n' }}\n {%- if args_value is string %}\n {%- set _av = args_value %}\n {%- else %}\n {%- set _av = args_value | tojson %}\n {%- endif %}\n {%- if max_tool_arg_chars > 0 and _av | length > max_tool_arg_chars %}\n {{- _av[:max_tool_arg_chars] + '\\n[TRUNCATED - original length ' ~ (_av | length | string) ~ ' chars]' }}\n {%- else %}\n {{- _av }}\n {%- endif %}\n {{- '\\n</parameter>\\n' }}\n {%- endfor %}\n {%- else %}\n {%- if tc.arguments is string %}\n {%- set _raw_args = tc.arguments %}\n {%- else %}\n {%- set _raw_args = tc.arguments | tojson %}\n {%- endif %}\n {%- if _raw_args %}\n {%- if max_tool_arg_chars > 0 and _raw_args | length > max_tool_arg_chars %}\n {{- _raw_args[:max_tool_arg_chars] + '\\n[TRUNCATED - original length ' ~ (_raw_args | length | string) ~ ' chars]' }}\n {%- else %}\n {{- _raw_args }}\n {%- endif %}\n {%- endif %}\n {%- endif %}\n {%- endif %}\n {{- '</function>\\n</tool_call>' }}\n {%- endif %}\n {%- endfor %}\n {%- endif %}\n {{- '<|im_end|>\\n' }}\n {%- elif message.role == 'tool' %}\n {%- set _content_lower = content | lower %}\n {%- set _content_head = _content_lower[:120] %}\n {%- set _is_code_or_grep = ('throw new ' in _content_lower or 'throw error' in _content_lower or 'console.error' in _content_lower or 'logger.error' in _content_lower or 'logging.error' in _content_lower or 'import ' in _content_head or 'def ' in _content_head or 'function ' in _content_head) %}\n {%- set _exit_code_zero = ('exit code: 0' in _content_head or 'process exited with code 0' in _content_head) %}\n {%- set _error_field_ok = ('\"error\": null' in _content_head or '\"error\":null' in _content_head or '\"error\": false' in _content_head or '\"error\":false' in _content_head or '\"error\": \"\"' in _content_head or '\"error\":\"\"' in _content_head) %}\n {%- set _strong_error = (('\"error\":' in _content_head and not _error_field_ok) or '\"status\": \"error\"' in _content_head or '\"status\":\"error\"' in _content_head or 'traceback (most recent call last):' in _content_head or 'command not found' in _content_head or 'invalid syntax' in _content_head or 'fatal:' in _content_head or '404 not found' in _content_head or 'rate limit' in _content_head or 'connection refused' in _content_head or 'timed out' in _content_head or (('exit code: ' in _content_head or 'process exited with code' in _content_head) and not _exit_code_zero) or _content_head.startswith('exception:') or _content_head.startswith('failed to ')) %}\n {%- set _weak_error = ('error:' in _content_head or 'err!' in _content_head) %}\n {%- set _weak_suppressed = ('$ ' in _content_head or 'took ' in _content_head or content | length >= 600) %}\n {%- if not _is_code_or_grep and (_strong_error or (_weak_error and not _weak_suppressed)) %}\n {%- set ns2.consecutive_failures = ns2.consecutive_failures + 1 %}\n {%- else %}\n {%- set ns2.consecutive_failures = 0 %}\n {%- endif %}\n {%- if ns2.prev_role != 'tool' %}\n {{- '<|im_start|>user' }}\n {%- endif %}\n {%- if max_tool_response_chars > 0 and content | length > max_tool_response_chars %}\n {%- set content = content[:max_tool_response_chars] + '\\n[TRUNCATED - original length ' ~ (content | length | string) ~ ' chars]' %}\n {%- endif %}\n {{- '\\n<tool_response>\\n' + content }}\n {%- if ns2.consecutive_failures >= 2 %}\n {{- '\\n\\n⚠️ SYSTEM WARNING: ' ~ ns2.consecutive_failures ~ ' consecutive tool errors detected. Your previous approach is incorrect. You MUST use a fundamentally different approach or corrected arguments.' }}\n {%- elif ns2.consecutive_failures == 1 %}\n {{- '\\n\\n⚠️ SYSTEM WARNING: The previous tool call returned an error. Diagnose the failure and retry with completely corrected arguments.' }}\n {%- endif %}\n {{- '\\n</tool_response>' }}\n {%- if loop.last %}\n {{- '<|im_end|>\\n' }}\n {%- else %}\n {%- set _next_role = _msgs[loop.index0 + 1].role %}\n {%- if _next_role != 'tool' %}\n {{- '<|im_end|>\\n' }}\n {%- endif %}\n {%- endif %}\n {%- else %}\n {{- '<|im_start|>user\\n[' + message.role + ']: ' + content + '<|im_end|>\\n' }}\n {%- endif %}\n {%- set ns2.prev_role = message.role %}\n{%- endfor %}\n{%- set _add_gen = (add_generation_prompt in (true, 'true', 'True', 1, '1', 'on')) if add_generation_prompt is defined else false %}\n{%- if _add_gen %}\n {{- '<|im_start|>assistant\\n' }}\n {%- if not ns_state.thinking %}\n {{- '<think>\\n\\n</think>\\n\\n' }}\n {%- else %}\n {{- '<think>\\n' }}\n {%- endif %}\n{%- endif %}\n"
|
| 299 |
+
}
|