Skip to content

Instantly share code, notes, and snippets.

@adstastic
Created August 5, 2025 10:07
Show Gist options
  • Select an option

  • Save adstastic/71632f39f4ea8d7facc2eddf0e46b3fd to your computer and use it in GitHub Desktop.

Select an option

Save adstastic/71632f39f4ea8d7facc2eddf0e46b3fd to your computer and use it in GitHub Desktop.
LMStudio Jinja Prompt Template
{%- if messages[0]["role"] == "system" %}
{%- set system_message = messages[0]["content"] %}
{%- set loop_messages = messages[1:] %}
{%- else %}
{%- set loop_messages = messages %}
{%- endif %}
{%- if not tools is defined %}
{%- set tools = [] %}
{%- endif %}
<|im_start|>system
{%- if system_message is defined %}
{{- system_message }}
{%- else %}
You are Qwen, a helpful AI assistant.
{%- endif %}
{%- if tools is iterable and tools | length > 0 %}
You have access to the following tools. To use a tool, you MUST respond with a single, valid JSON object in the specified format.
# Tools Available
```json
{{ tools | tojson(indent=2) }}
Tool Call Format
When you decide to call a tool, you MUST respond with nothing but a single JSON object. Do not add any other text, markdown, or explanations before or after the JSON.
The JSON object must have a tool key with the name of the function to call, and an arguments key containing an object of the parameters.
For example:
JSON
{
"tool": "name_of_the_function",
"arguments": {
"parameter_name_1": "value_1",
"parameter_name_2": "value_2"
}
}
{%- endif -%}
<|im_end|>
{%- for message in loop_messages %}
{%- if message.role == "user" %}
<|im_start|>user
{{ message.content }}<|im_end|>
{%- elif message.role == "assistant" %}
{%- if message.tool_calls is defined and message.tool_calls is iterable and message.tool_calls | length > 0 %}
<|im_start|>assistant
{#- This block formats the AI's tool call into the JSON format it's expected to generate. #}
{#- It assumes the first tool call is the one to be displayed. #}
{%- set tool_call = message.tool_calls[0].function %}
{%- set arguments_json = tool_call.arguments | fromjson %}
{%- set json_output = {"tool": tool_call.name, "arguments": arguments_json} %}
{{- json_output | tojson(indent=2) -}}
<|im_end|>
{%- else %}
<|im_start|>assistant
{{ message.content }}<|im_end|>
{%- endif %}
{%- elif message.role == "tool" %}
<|im_start|>tool
{{ message.content | trim }}
<|im_end|>
{%- endif %}
{%- endfor %}
{%- if add_generation_prompt %}
<|im_start|>assistant
{%- endif %}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment