{#- Yılmaz Chat Template --------------------- Kendi tasarımımız olan, ChatML'e benzer ama kendi markalı özel token'larımızı kullanan bir sohbet şablonu. Tur biçimi: <|yilmaz_start|>ROL İÇERİK<|yilmaz_end|> Desteklenen roller: system, user, assistant, tool Opsiyonel: thinking (<|yilmaz_think|> ... <|yilmaz_think_end|>) Opsiyonel: tool calling (<|yilmaz_tool_call|> ... <|yilmaz_tool_call_end|>) content alanı hem düz metin (string) hem de [{"type": "text", "text": "..."}] biçiminde liste olabilir; bu şablon şu an yalnızca metin içeriği destekler (görsel/ses/video token'ı BPE_Magibu'da tanımlı olmadığı için kapsam dışıdır). -#} {%- macro render_content(content) -%} {%- if content is string -%} {{- content -}} {%- elif content is iterable and content is not mapping -%} {%- for item in content -%} {%- if item.type == 'text' -%} {{- item.text -}} {%- else -%} {{- raise_exception('Bu şablon şu an sadece metin içeriği destekliyor, gelen tür: ' + (item.type | default('bilinmeyen'))) -}} {%- endif -%} {%- endfor -%} {%- elif content is none or content is undefined -%} {{- '' -}} {%- else -%} {{- raise_exception('Beklenmeyen content türü.') -}} {%- endif -%} {%- endmacro -%} {%- if not messages %} {{- raise_exception('messages listesi boş olamaz.') }} {%- endif %} {%- set ns = namespace(messages=messages) %} {#- Tool tanımları varsa, ilk sistem mesajı olarak enjekte edilir -#} {%- if tools is defined and tools %} {{- '<|yilmaz_start|>system\n' }} {{- 'Aşağıdaki fonksiyonlara erişimin var:\n\n' }} {%- for tool in tools %} {{- '\n' + (tool | tojson) }} {%- endfor %} {{- '\n\n\n' }} {{- 'Bir fonksiyon çağırman gerektiğinde SADECE şu formatta yanıt ver:\n' }} {{- '<|yilmaz_tool_call|>{"name": "fonksiyon_adi", "arguments": {"param": "değer"}}<|yilmaz_tool_call_end|>\n\n' }} {{- 'Çağrıdan önce kısa bir açıklama yazabilirsin, ama çağrıdan SONRA başka metin ekleme. ' }} {{- 'Fonksiyona ihtiyaç yoksa normal şekilde, mevcut bilginle cevap ver.' }} {%- if ns.messages[0].role == 'system' %} {{- '\n\n' + (render_content(ns.messages[0].content) | trim) }} {%- set ns.messages = ns.messages[1:] %} {%- endif %} {{- '<|yilmaz_end|>\n' }} {%- elif ns.messages[0].role == 'system' %} {{- '<|yilmaz_start|>system\n' + (render_content(ns.messages[0].content) | trim) + '<|yilmaz_end|>\n' }} {%- set ns.messages = ns.messages[1:] %} {%- endif %} {%- for message in ns.messages %} {%- if message.role == 'user' %} {{- '<|yilmaz_start|>user\n' + (render_content(message.content) | trim) + '<|yilmaz_end|>\n' }} {%- elif message.role == 'assistant' %} {{- '<|yilmaz_start|>assistant\n' }} {#- content'i çöz -#} {%- set content = render_content(message.content) | trim %} {#- Reasoning / thinking: önce ayrı alan, yoksa content içine gömülü <|yilmaz_think|>...<|yilmaz_think_end|> aranır -#} {%- set reasoning = '' %} {%- if message.reasoning_content is defined and message.reasoning_content %} {%- set reasoning = message.reasoning_content %} {%- elif '<|yilmaz_think_end|>' in content %} {%- set reasoning = content.split('<|yilmaz_think_end|>')[0].split('<|yilmaz_think|>')[-1] | trim %} {%- set content = content.split('<|yilmaz_think_end|>')[-1] | trim %} {%- endif %} {%- if reasoning %} {{- '<|yilmaz_think|>\n' + (reasoning | trim) + '\n<|yilmaz_think_end|>\n\n' }} {%- endif %} {%- if content %} {{- content }} {%- endif %} {#- Tool çağrıları (varsa) -#} {%- if message.tool_calls is defined and message.tool_calls %} {%- for tool_call in message.tool_calls %} {%- if tool_call.function is defined %} {%- set tool_call = tool_call.function %} {%- endif %} {{- '\n<|yilmaz_tool_call|>' }} {{- ({'name': tool_call.name, 'arguments': tool_call.arguments}) | tojson }} {{- '<|yilmaz_tool_call_end|>' }} {%- endfor %} {%- endif %} {{- '<|yilmaz_end|>\n' }} {%- elif message.role == 'tool' %} {{- '<|yilmaz_start|>user\n' }} {{- '<|yilmaz_tool_result|>' + (render_content(message.content) | trim) + '<|yilmaz_tool_result_end|>' }} {{- '<|yilmaz_end|>\n' }} {%- else %} {{- raise_exception('Bilinmeyen mesaj rolü: ' + message.role) }} {%- endif %} {%- endfor %} {%- if add_generation_prompt %} {{- '<|yilmaz_start|>assistant\n' }} {%- if enable_thinking is defined and enable_thinking %} {{- '<|yilmaz_think|>\n' }} {%- endif %} {%- endif %}