| |
| |
| {%- if tools %} |
| {{- '<|im_start|>system\n' }} |
| {{- """ |
| You are an expert tutor for multiple-choice questions. For each question, you will use a transparent chain-of-thought approach, thinking aloud in clear, sequential steps as you reason through the problem. Follow this pattern every time: |
| |
| 1. Restate the question in your own words. |
| 2. List the answer choices (A, B, C, etc.). |
| 3. Work through your reasoning in numbered “Thought” steps, showing how you interpret facts, apply principles, eliminate incorrect options, and compare remaining answers. |
| 4. Include any calculations, definitions, or formulas you use. |
| |
| After your chain of thought, conclude with: |
| **Answer: X** |
| where X is the correct letter choice, followed by a one-sentence summary of why that choice is correct. |
| |
| Do not skip directly to the answer—always expose your full reasoning process first. |
| """ + '\n' }} |
| {{- '<|im_end|>\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\nFor each function call, return a json object with function name and arguments within `<tool_call></tool_call>` XML tags:\n<tool_call>\n{\"name\": <function-name>, \"arguments\": <args-json-object>}\n</tool_call>\n" }} |
| {%- else %} |
| {%- if messages[0].role == 'system' %} |
| {{- '<|im_start|>system\n' }} |
| {{- messages[0].content }} |
| {{- '<|im_end|>\n' }} |
| {%- endif %} |
| {%- endif %} |
| |
| |
| {%- set ns = namespace(multi_step_tool=true, last_query_index=messages|length - 1) %} |
| {%- for message in messages[::-1] %} |
| {%- set index = (messages|length - 1) - loop.index0 %} |
| {%- if ns.multi_step_tool and message.role == "user" 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 %} |
| {%- for message in messages %} |
| {%- if (message.role == "user") or (message.role == "system" and not loop.first) %} |
| {{- '<|im_start|>' + message.role + '\n' + message.content + '<|im_end|>\n' }} |
| {%- elif message.role == "assistant" %} |
| |
| {%- elif message.role == "tool" %} |
| |
| {%- endif %} |
| {%- endfor %} |
| |