MCQ_Generator / chat_template.jinja
sid22669's picture
Upload tokenizer
d67a3ea verified
{%- set system_message = "## Identity:
You are an MCQ Generation Assistant, designed to generate precise and domain-relevant multiple-choice questions (MCQs) based on user input.
## Capabilities:
You are capable of generating high-quality MCQs strictly within the following domains:
- Python
- Excel
- Statistics
- Power BI
- Tableau
## Limitations:
- You must not respond to any prompts outside MCQ generation.
- You must not generate MCQs outside the approved domains.
- If the input query is invalid or unrelated, respond with \"Error\" (string only).
## Output Format:
Your output will always be a Python list of dictionaries, each dictionary containing the following keys:
- question_no: (int) The serial number of the question
- Question: (str) The question text
- Option_a, Option_b, Option_c, Option_d: (str) Four options for the user to choose from
- correct_answer: (str) The correct option’s full text (not just the letter)
## Example Input & Output:
User Input:
Generate 1 MCQ on Python strings.
Expected Output:
[
{
'question_no': 1,
'Question': 'What is the purpose of the square brackets in indexing a string in Python?',
'Option_a': 'To access the first character of the string',
'Option_b': 'To access the last character of the string',
'Option_c': 'To access the character at a specific position in the string',
'Option_d': 'To access the character at the beginning of the string',
'correct_answer': 'To access the character at a specific position in the string'
}
]
## Invalid Example:
User Input:
Who are you?
Expected Output:
\"Error\"" %}
{%- set loop_messages = messages %}
{%- if not tools is defined %}
{%- set tools = none %}
{%- endif %}
{%- set user_messages = loop_messages | selectattr("role", "equalto", "user") | list %}
{%- set ns = namespace() %}
{%- set ns.index = 0 %}
{%- for message in loop_messages %}
{%- if not (message.role == "tool" or message.role == "tool_results" or (message.tool_calls is defined and message.tool_calls is not none)) %}
{%- if (message["role"] == "user") != (ns.index % 2 == 0) %}
{{- raise_exception("After the system message, conversation roles must alternate user/assistant/user/assistant/...") }}
{%- endif %}
{%- set ns.index = ns.index + 1 %}
{%- endif %}
{%- endfor %}
{{- bos_token }}
{%- for message in loop_messages %}
{%- if message["role"] == "user" %}
{%- if tools is not none and (message == user_messages[-1]) %}
{{- "[AVAILABLE_TOOLS] [" }}
{%- for tool in tools %}
{%- set tool = tool.function %}
{{- '{"type": "function", "function": {' }}
{%- for key, val in tool.items() if key != "return" %}
{%- if val is string %}
{{- '"' + key + '": "' + val + '"' }}
{%- else %}
{{- '"' + key + '": ' + val|tojson }}
{%- endif %}
{%- if not loop.last %}
{{- ", " }}
{%- endif %}
{%- endfor %}
{{- "}}" }}
{%- if not loop.last %}
{{- ", " }}
{%- else %}
{{- "]" }}
{%- endif %}
{%- endfor %}
{{- "[/AVAILABLE_TOOLS]" }}
{%- endif %}
{%- if loop.last %}
{{- "[INST] " + system_message + "
" + message["content"] + "[/INST]" }}
{%- else %}
{{- "[INST] " + message["content"] + "[/INST]" }}
{%- endif %}
{%- elif message.tool_calls is defined and message.tool_calls is not none %}
{{- "[TOOL_CALLS] [" }}
{%- for tool_call in message.tool_calls %}
{%- set out = tool_call.function|tojson %}
{{- out[:-1] }}
{%- if not tool_call.id is defined or tool_call.id|length != 9 %}
{{- raise_exception("Tool call IDs should be alphanumeric strings with length 9!") }}
{%- endif %}
{{- ', "id": "' + tool_call.id + '"}' }}
{%- if not loop.last %}
{{- ", " }}
{%- else %}
{{- "]" + eos_token }}
{%- endif %}
{%- endfor %}
{%- elif message["role"] == "assistant" %}
{{- " " + message["content"]|trim + eos_token}}
{%- elif message["role"] == "tool_results" or message["role"] == "tool" %}
{%- if message.content is defined and message.content.content is defined %}
{%- set content = message.content.content %}
{%- else %}
{%- set content = message.content %}
{%- endif %}
{{- '[TOOL_RESULTS] {"content": ' + content|string + ", " }}
{%- if not message.tool_call_id is defined or message.tool_call_id|length != 9 %}
{{- raise_exception("Tool call IDs should be alphanumeric strings with length 9!") }}
{%- endif %}
{{- '"call_id": "' + message.tool_call_id + '"}[/TOOL_RESULTS]' }}
{%- else %}
{{- raise_exception("Only user and assistant roles are supported!") }}
{%- endif %}
{%- endfor %}