user_gemma_3_4b_it / chat_template.jinja
planeB's picture
Add files using upload-large-folder tool
3b9dba0 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 + '
' -%}
{%- 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 + '
' + (first_user_prefix if loop.first else "") }}
{%- if message.content is string -%}
{# This handles regular assistant/model responses #}
{{ message.content | trim }}
{%- elif message.content is mapping -%}
# Category
{{ message.content.category | trim }}{{ "\n\n" }}
# User Persona
{{ message.content.user_persona | trim }}{{ "\n" }}
{%- if message.content.interacted_items | length > 0 -%}
{{ "\n\n" }}# Interaction history
{%- for item in message.content.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: {{ message.content.target_item.item_name | trim }}
## Description: {{ message.content.target_item.description | trim }}
## Visual Description: {{ message.content.target_item.visual_description | trim }}
## Review: {{ message.content.target_item.review | trim }}{{ "\n" }}
{%- if message.content.messages | length > 0 -%}
{{ "\n\n" }}# Conversation so far
{%- for turn in message.content.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." }}
{%- else -%}
{{ "\nGenerate the first user message based on the above information." }}
{%- endif -%}
{%- else -%}
{{ raise_exception("Invalid content type: must be string, mapping (dict), or iterable (list).") }}
{%- endif -%}
{{ '<end_of_turn>
' }}
{%- endfor -%}
{%- if add_generation_prompt -%}
{{'<start_of_turn>model
'}}
{%- endif -%}