Views
No views yet
1messages = [
2 {
3 "role": "system",
4 "content": "Sen Türkçe cevap veren yardımcı bir asistansın.",
5 },
6 {
7 "role": "user",
8 "content": "Türkiye'nin başkenti neresidir?",
9 },
10]1<|begin_of_chat|>
2<|system|>
3Sen Türkçe cevap veren yardımcı bir asistansın.
4<|end_message|>
5<|user|>
6Türkiye'nin başkenti neresidir?
7<|end_message|>
8<|assistant|><|assistant|> etiketi, sıradaki cevabın model tarafından
üretilmesi gerektiğini belirtir.| Rol | Açıklama |
|---|---|
system | Modelin genel davranışını belirleyen sistem talimatı |
developer | Uygulama geliştiricisine ait ek talimatlar |
user | Kullanıcı tarafından gönderilen mesaj |
assistant | Dil modeli veya asistan tarafından oluşturulan mesaj |
tool | Bir araç çağrısından dönen sonuç |
add_generation_prompt desteğiapply_chat_template() uyumluluğu1custom-chat-template/
2├── chat_template.jinja
3├── test_template.py
4├── test_huggingface.py
5├── requirements.txt
6├── README.md
7└── .gitignorechat_template.jinjatest_template.pytest_huggingface.pyapply_chat_template() fonksiyonuyla test eder.cd custom-chat-templatepython3 -m venv .venvsource .venv/bin/activatepip install -r requirements.txtpython test_template.py1######################################################################
2TEST ÖZETİ
3######################################################################
4Başarılı test: 8/8
5🎉 Bütün testler başarıyla tamamlandı.python test_huggingface.pygoogle/gemma-2-9b-it modelinin yalnızca tokenizer dosyaları
kullanılır. Model ağırlıkları indirilmez ve model inference işlemi
yapılmaz.1######################################################################
2✅ CUSTOM TEMPLATE HUGGING FACE İLE BAŞARIYLA ÇALIŞTI
3######################################################################apply_chat_template() ile metin oluşturulmasıtools parametresi aracılığıyla verilir:1tools = [
2 {
3 "type": "function",
4 "function": {
5 "name": "multiply",
6 "description": "Verilen iki sayıyı çarpar.",
7 "parameters": {
8 "type": "object",
9 "properties": {
10 "a": {"type": "number"},
11 "b": {"type": "number"},
12 },
13 "required": ["a", "b"],
14 },
15 },
16 }
17]1<|available_tools|>
2...
3<|end_available_tools|>1<|tool_call|>
2{
3 "id": "call_001",
4 "type": "function",
5 "function": {
6 "name": "multiply",
7 "arguments": {
8 "a": 12,
9 "b": 8
10 }
11 }
12}
13<|end_tool_call|>1<|tool_result|>
2{
3 "role": "tool",
4 "name": "multiply",
5 "content": "96"
6}
7<|end_tool_result|>1{
2 "role": "user",
3 "content": [
4 {
5 "type": "text",
6 "text": "Bu görseli ve sesi incele:",
7 },
8 {
9 "type": "image",
10 },
11 {
12 "type": "audio",
13 },
14 {
15 "type": "video",
16 },
17 ],
18}1<|image|>
2<|audio|>
3<|video|>user mesajı gönderilmesisystem veya developer mesajı gelmesirole veya gerekli content alanının bulunmaması1<bos>
2...
3<eos>1<|begin_of_chat|>
2<|end_message|>add_generation_prompt=True kullanıldığında sohbetin sonuna:<|assistant|>1from pathlib import Path
2
3from transformers import AutoTokenizer
4
5
6tokenizer = AutoTokenizer.from_pretrained(
7 "google/gemma-2-9b-it"
8)
9
10template = Path(
11 "chat_template.jinja"
12).read_text(encoding="utf-8")
13
14tokenizer.chat_template = template
15
16messages = [
17 {
18 "role": "system",
19 "content": "Sorulara Türkçe cevap ver.",
20 },
21 {
22 "role": "user",
23 "content": "Merhaba!",
24 },
25]
26
27rendered_chat = tokenizer.apply_chat_template(
28 messages,
29 tokenize=False,
30 add_generation_prompt=True,
31)
32
33print(rendered_chat)| Test | Sonuç |
|---|---|
| Doğrudan Jinja2 testi | Başarılı |
| Normal sohbet | Başarılı |
| Developer rolü | Başarılı |
| Tool calling | Başarılı |
| Çok modlu içerik | Başarılı |
| BOS/EOS tokenları | Başarılı |
| Hatalı rol kontrolleri | Başarılı |
| Hugging Face render testi | Başarılı |
| Hugging Face tokenizasyon testi | Başarılı |
| Template dışa aktarma testi | Başarılı |
| Gemma 2 9B tokenizer testi | Başarılı |
1Jinja2 otomatik testleri: 8/8 başarılı
2Hugging Face uyumluluk testi: Başarılı
3Gemma 2 9B tokenizer testi: Başarılı
4Tool calling testi: Başarılı
5Multimodal içerik testi: Başarılı