Image-Text-to-Text
Transformers
Safetensors
English
gemma3
uncensored
heretic
abliterated
unsloth
finetune
All use cases
bfloat16
creative
creative writing
fiction writing
plot generation
sub-plot generation
story generation
scene continue
storytelling
fiction story
science fiction
romance
all genres
story
writing
vivid prosing
vivid writing
fiction
conversational
text-generation-inference
Upload 2 files
Browse files- chat_template.jinja +47 -59
- chat_template_thinking.jinja +59 -0
chat_template.jinja
CHANGED
|
@@ -1,59 +1,47 @@
|
|
| 1 |
-
{{ bos_token }}
|
| 2 |
-
{
|
| 3 |
-
{%-
|
| 4 |
-
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
{%-
|
| 8 |
-
{%- set first_user_prefix =
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
{%- endif -%}
|
| 12 |
-
{%- set loop_messages = messages[1:] -%}
|
| 13 |
-
{%- else -%}
|
| 14 |
-
{
|
| 15 |
-
{%- set
|
| 16 |
-
|
| 17 |
-
{%-
|
| 18 |
-
|
| 19 |
-
{
|
| 20 |
-
{%-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
{
|
| 27 |
-
|
| 28 |
-
{%-
|
| 29 |
-
|
| 30 |
-
{
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
{%-
|
| 39 |
-
{{
|
| 40 |
-
{%- endif -%}
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
{
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
{{ '<image>' }}
|
| 49 |
-
{%- elif item['type'] == 'text' -%}
|
| 50 |
-
{{ item['text'] | trim }}
|
| 51 |
-
{%- endif -%}
|
| 52 |
-
{%- endfor -%}
|
| 53 |
-
{%- endif -%}
|
| 54 |
-
{{ '<end_of_turn>\n' }}
|
| 55 |
-
{%- endfor -%}
|
| 56 |
-
|
| 57 |
-
{%- if add_generation_prompt -%}
|
| 58 |
-
{{ '<start_of_turn>model\n<think>\n' }}
|
| 59 |
-
{%- endif -%}
|
|
|
|
| 1 |
+
{{ bos_token }}
|
| 2 |
+
{%- if messages[0]['role'] == 'system' -%}
|
| 3 |
+
{%- if messages[0]['content'] is string -%}
|
| 4 |
+
{%- set first_user_prefix = messages[0]['content'] + '
|
| 5 |
+
|
| 6 |
+
' -%}
|
| 7 |
+
{%- else -%}
|
| 8 |
+
{%- set first_user_prefix = messages[0]['content'][0]['text'] + '
|
| 9 |
+
|
| 10 |
+
' -%}
|
| 11 |
+
{%- endif -%}
|
| 12 |
+
{%- set loop_messages = messages[1:] -%}
|
| 13 |
+
{%- else -%}
|
| 14 |
+
{%- set first_user_prefix = "" -%}
|
| 15 |
+
{%- set loop_messages = messages -%}
|
| 16 |
+
{%- endif -%}
|
| 17 |
+
{%- for message in loop_messages -%}
|
| 18 |
+
{%- if (message['role'] == 'user') != (loop.index0 % 2 == 0) -%}
|
| 19 |
+
{{ raise_exception("Conversation roles must alternate user/assistant/user/assistant/...") }}
|
| 20 |
+
{%- endif -%}
|
| 21 |
+
{%- if (message['role'] == 'assistant') -%}
|
| 22 |
+
{%- set role = "model" -%}
|
| 23 |
+
{%- else -%}
|
| 24 |
+
{%- set role = message['role'] -%}
|
| 25 |
+
{%- endif -%}
|
| 26 |
+
{{ '<start_of_turn>' + role + '
|
| 27 |
+
' + (first_user_prefix if loop.first else "") }}
|
| 28 |
+
{%- if message['content'] is string -%}
|
| 29 |
+
{{ message['content'] | trim }}
|
| 30 |
+
{%- elif message['content'] is iterable -%}
|
| 31 |
+
{%- for item in message['content'] -%}
|
| 32 |
+
{%- if item['type'] == 'image' -%}
|
| 33 |
+
{{ '<start_of_image>' }}
|
| 34 |
+
{%- elif item['type'] == 'text' -%}
|
| 35 |
+
{{ item['text'] | trim }}
|
| 36 |
+
{%- endif -%}
|
| 37 |
+
{%- endfor -%}
|
| 38 |
+
{%- else -%}
|
| 39 |
+
{{ raise_exception("Invalid content type") }}
|
| 40 |
+
{%- endif -%}
|
| 41 |
+
{{ '<end_of_turn>
|
| 42 |
+
' }}
|
| 43 |
+
{%- endfor -%}
|
| 44 |
+
{%- if add_generation_prompt -%}
|
| 45 |
+
{{'<start_of_turn>model
|
| 46 |
+
'}}
|
| 47 |
+
{%- endif -%}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
chat_template_thinking.jinja
ADDED
|
@@ -0,0 +1,59 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{{ bos_token }}
|
| 2 |
+
{# Define the hardcoded thinking instructions #}
|
| 3 |
+
{%- set system_instruction = "Think deeply and carefully about the user's request. Compose your thoughts about the user's prompt between <think> and </think> tags, then output the final answer based on your thoughts." -%}
|
| 4 |
+
|
| 5 |
+
{%- if messages[0]['role'] == 'system' -%}
|
| 6 |
+
{# If the user provided a system prompt, prepend our instruction to it #}
|
| 7 |
+
{%- if messages[0]['content'] is string -%}
|
| 8 |
+
{%- set first_user_prefix = system_instruction + '\n\n' + messages[0]['content'] + '\n\n' -%}
|
| 9 |
+
{%- else -%}
|
| 10 |
+
{%- set first_user_prefix = system_instruction + '\n\n' + messages[0]['content'][0]['text'] + '\n\n' -%}
|
| 11 |
+
{%- endif -%}
|
| 12 |
+
{%- set loop_messages = messages[1:] -%}
|
| 13 |
+
{%- else -%}
|
| 14 |
+
{# If no system prompt exists, just use our instruction #}
|
| 15 |
+
{%- set first_user_prefix = system_instruction + '\n\n' -%}
|
| 16 |
+
{%- set loop_messages = messages -%}
|
| 17 |
+
{%- endif -%}
|
| 18 |
+
|
| 19 |
+
{%- for message in loop_messages -%}
|
| 20 |
+
{%- if (message['role'] == 'user') != (loop.index0 % 2 == 0) -%}
|
| 21 |
+
{{ raise_exception("Conversation roles must alternate user/assistant/user/assistant/...") }}
|
| 22 |
+
{%- endif -%}
|
| 23 |
+
|
| 24 |
+
{%- if (message['role'] == 'assistant') -%}
|
| 25 |
+
{%- set role = "model" -%}
|
| 26 |
+
{%- else -%}
|
| 27 |
+
{%- set role = message['role'] -%}
|
| 28 |
+
{%- endif -%}
|
| 29 |
+
|
| 30 |
+
{{ '<start_of_turn>' + role + '\n' }}
|
| 31 |
+
|
| 32 |
+
{# Inject the system prefix only into the very first turn #}
|
| 33 |
+
{%- if loop.first -%}
|
| 34 |
+
{{ first_user_prefix }}
|
| 35 |
+
{%- endif -%}
|
| 36 |
+
|
| 37 |
+
{# Check for a 'thought' key to wrap in tags if it exists in history #}
|
| 38 |
+
{%- if message['thought'] is defined and message['thought'] -%}
|
| 39 |
+
{{ '<think>\n' + (message['thought'] | trim) + '\n</think>\n' }}
|
| 40 |
+
{%- endif -%}
|
| 41 |
+
|
| 42 |
+
{# Render message content #}
|
| 43 |
+
{%- if message['content'] is string -%}
|
| 44 |
+
{{ message['content'] | trim }}
|
| 45 |
+
{%- elif message['content'] is iterable -%}
|
| 46 |
+
{%- for item in message['content'] -%}
|
| 47 |
+
{%- if item['type'] == 'image' -%}
|
| 48 |
+
{{ '<image>' }}
|
| 49 |
+
{%- elif item['type'] == 'text' -%}
|
| 50 |
+
{{ item['text'] | trim }}
|
| 51 |
+
{%- endif -%}
|
| 52 |
+
{%- endfor -%}
|
| 53 |
+
{%- endif -%}
|
| 54 |
+
{{ '<end_of_turn>\n' }}
|
| 55 |
+
{%- endfor -%}
|
| 56 |
+
|
| 57 |
+
{%- if add_generation_prompt -%}
|
| 58 |
+
{{ '<start_of_turn>model\n<think>\n' }}
|
| 59 |
+
{%- endif -%}
|