user_gemma_3_12b_it / chat_template.jinja
planeB's picture
Add files using upload-large-folder tool
292b8bc verified
{{ bos_token }}
{%- set system_prompt = "You are an advanced user simulator. Your objective is to generate realistic and coherent user responses in a dialogue with a recommendation system based on the user persona, interaction history and target item provided.
Use the following guidelines:
1. Adhere to the user persona: The user's behavior, tone, and responses must align with the specified persona.
2. Use the tone inferred from the user's past reviews in the interaction history.
3. Ensure that the user's responses are contextually relevant to the ongoing conversation and the target item.
4. Maintain coherence and natural flow in the dialogue." -%}
{%- set first_user_prefix = system_prompt + '\n\n' -%}
{%- set loop_messages = messages -%}
{%- for message in loop_messages -%}
{%- if (message['role'] == 'user') != (loop.index0 % 2 == 0) -%}
{{ raise_exception("Conversation roles must alternate user/assistant/user/assistant/...") }}
{%- endif -%}
{%- if (message['role'] == 'assistant') -%}
{%- set role = "model" -%}
{%- elif (message['role'] == 'system') -%}
{{ raise_exception("This template is hardcoded and does not accept 'system' messages.") }}
{%- else -%}
{%- set role = message['role'] -%}
{%- endif -%}
{{ '<start_of_turn>' + role + '\n' + (first_user_prefix if loop.first else "") }}
{# --- START: SENIOR ENGINEER REFACTOR FOR DATA PARSING --- #}
{%- set content_data = message.content -%}
{%- set is_ninja_payload = false -%}
{# Check if content is a string that looks like JSON (starts with { and contains target_item) #}
{%- if message.content is string -%}
{%- if message.content | trim | first == '{' and 'target_item' in message.content -%}
{%- set content_data = message.content | fromjson -%}
{%- set is_ninja_payload = true -%}
{%- endif -%}
{%- elif message.content is mapping -%}
{# Fallback for internal testing where dicts might be passed directly #}
{%- set is_ninja_payload = true -%}
{%- endif -%}
{# --- END: DATA PARSING --- #}
{%- if not is_ninja_payload -%}
{# This handles regular assistant/model responses or simple user strings #}
{{ message.content | trim }}
{%- else -%}
{# This handles the complex Ninja User Simulator inputs #}
# Category
{{ content_data.category | trim }}{{ "\n\n" }}
# User Persona
{{ content_data.user_persona | trim }}{{ "\n" }}
{%- if content_data.interacted_items | length > 0 -%}
{{ "\n\n" }}# Interaction history
{%- for item in content_data.interacted_items -%}
{{ "\n" }}## Item Name: {{ item.item_name | trim }}
## Description: {{ item.description | trim }}
## Visual Description: {{ item.visual_description | trim }}
## Review: {{ item.review | trim }}{{ "\n" }}
{%- endfor -%}
{%- endif -%}
{{ "\n" }}
# Target item
## Item Name: {{ content_data.target_item.item_name | trim }}
## Description: {{ content_data.target_item.description | trim }}
## Visual Description: {{ content_data.target_item.visual_description | trim }}
## Review: {{ content_data.target_item.review | trim }}{{ "\n" }}
{%- if content_data.messages | length > 0 -%}
{{ "\n\n" }}# Conversation so far
{%- for turn in content_data.messages[-2:] -%}
{%- if turn['role'] == 'assistant' -%}
{{ "\n" }}CRS: "{{turn['content'] | trim}}"
{%- else -%}
{{ "\n" }}USR: "{{turn['content'] | trim}}"
{%- endif -%}
{%- endfor -%}
{{ "\n" }}
{{ "Generate the next user response based on the above information. Remember to accept only the target item. Reject any other item." }}
{%- else -%}
{{ "\nGenerate the first user message based on the above information." }}
{%- endif -%}
{%- endif -%}
{{ '<end_of_turn>\n' }}
{%- endfor -%}
{%- if add_generation_prompt -%}
{{'<start_of_turn>model\n'}}
{%- endif -%}