Text Generation
Transformers
Turkish
English
chat-template
jinja2
prompt-format
pharmacy
tool-calling
rag
conversational
Instructions to use menesnas/ChatTemplate with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use menesnas/ChatTemplate with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="menesnas/ChatTemplate") messages = [ {"role": "user", "content": "Who are you?"}, ] pipe(messages)# Load model directly from transformers import AutoModel model = AutoModel.from_pretrained("menesnas/ChatTemplate", device_map="auto") - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- vLLM
How to use menesnas/ChatTemplate with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "menesnas/ChatTemplate" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "menesnas/ChatTemplate", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }'Use Docker
docker model run hf.co/menesnas/ChatTemplate
- SGLang
How to use menesnas/ChatTemplate with SGLang:
Install from pip and serve model
# Install SGLang from pip: pip install sglang # Start the SGLang server: python3 -m sglang.launch_server \ --model-path "menesnas/ChatTemplate" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "menesnas/ChatTemplate", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }'Use Docker images
docker run --gpus all \ --shm-size 32g \ -p 30000:30000 \ -v ~/.cache/huggingface:/root/.cache/huggingface \ --env "HF_TOKEN=<secret>" \ --ipc=host \ lmsysorg/sglang:latest \ python3 -m sglang.launch_server \ --model-path "menesnas/ChatTemplate" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "menesnas/ChatTemplate", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }' - Docker Model Runner
How to use menesnas/ChatTemplate with Docker Model Runner:
docker model run hf.co/menesnas/ChatTemplate
File size: 4,830 Bytes
880081f 5a4ba7f | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 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 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 | ---
license: mit
language:
- tr
- en
library_name: transformers
tags:
- chat-template
- jinja2
- prompt-format
- pharmacy
- tool-calling
- rag
pipeline_tag: text-generation
---
# Pharmacy Prompt Serialization Format (PPSF) — Custom Jinja2 Chat Template
Bu proje, bir dil modelinin (LLM) kullanıcı, sistem, asistan ve araç (tool calling) mesajlarını doğru ayırt edebilmesi ve **Pharmacy Prompt Serialization Format (PPSF v1.0 / v1.1)** spesifikasyonuna uygun şekilde serileştirmesi için geliştirilmiş bir **Custom Jinja2 Chat Template** uygulamasıdır.
Hugging Face `transformers` kütüphanesinin `apply_chat_template()` fonksiyonu ile **%100 tam uyumlu** olarak çalışacak şekilde tasarlanmıştır.
---
## 🎯 Ödev Amacı ve Özellikler
- **Hugging Face Standartlarına Tam Uyumluluk:** Standart `messages` dizisini (`role`, `content`, `tool_calls`) ve `tools` listesini kabul eder.
- **Alan Spesifik Rol Tanımları (Pharmacy Protocol):**
- `system` $\rightarrow$ `@SYSTEM`
- `user` $\rightarrow$ `@PATIENT`
- `assistant` $\rightarrow$ `@PHARMACIST`
- `tool` $\rightarrow$ `@TOOL_RESPONSE`
- **Tool Calling (Araç Çağrısı) Desteği:**
- Mevcut araç tanımlarını `@TOOLS` bloğu altında ilan eder.
- Asistanın araç çağırma isteklerini `@TOOL_CALL` formatında formatlar.
- Araç yanıtlarını `@TOOL_RESPONSE` olarak bağlama ekler.
- **Geleceğe Uyumlu Metadata Desteği (PPSF v1.1):**
- Mesaj nesnesinde yer alan `metadata.reference` verilerini `@REFERENCE` bloğuna dönüştürür.
- Mesaj nesnesinde yer alan `metadata.thought` verilerini (Chain of Thought) `@THOUGHT` bloğuna dönüştürür.
---
## 📁 Proje Dosya Yapısı
```
Chat_Template/
├── chat_template.jinja # PPSF v1.0 / v1.1 Jinja2 şablon dosyası
├── main.py # Jinja2 ve Hugging Face AutoTokenizer test scripti
└── README.md # Proje dokümantasyonu
```
---
## 🚀 Kurulum ve Çalıştırma
### 1. Gereksinimler
Projeyi çalıştırmak için Python 3.8+ ve aşağıdaki kütüphanelerin kurulu olması yeterlidir:
```bash
pip install jinja2 transformers
```
### 2. Test Scriptini Çalıştırma
Tüm test senaryolarını (Standart sohbet, Tool Calling ve Metadata kullanımı) çalıştırmak için:
```bash
python main.py
```
---
## 💻 Kullanım Örnekleri
### Hugging Face `transformers` ile Kullanım
```python
from transformers import AutoTokenizer
# Herhangi bir tokenizer yüklendikten sonra özel şablon atanabilir:
tokenizer = AutoTokenizer.from_pretrained("gpt2")
with open("chat_template.jinja", "r", encoding="utf-8") as f:
tokenizer.chat_template = f.read()
messages = [
{"role": "system", "content": "Sen uzman bir eczacı yapay zekâsısın."},
{"role": "user", "content": "Boğazım ağrıyor."}
]
prompt = tokenizer.apply_chat_template(
messages,
add_generation_prompt=True,
tokenize=False
)
print(prompt)
```
**Üretilen Çıktı:**
```text
@FORMAT PPSF/1.0
@SYSTEM
Sen uzman bir eczacı yapay zekâsısın.
@PATIENT
Boğazım ağrıyor.
@PHARMACIST
```
---
### Tool Calling Senaryosu Örneği
**Girdi:**
```python
messages = [
{"role": "system", "content": "Sen uzman bir eczacı yapay zekâsısın."},
{"role": "user", "content": "Parol ne işe yarar?"},
{
"role": "assistant",
"content": None,
"tool_calls": [
{
"function": {
"name": "search_drug",
"arguments": {"drug": "Parol"}
}
}
]
},
{
"role": "tool",
"content": '{"drug": "Parol", "active_ingredient": "Parasetamol", "usage": "Ağrı kesici ve ateş düşürücü"}'
}
]
```
**Üretilen Çıktı:**
```text
@FORMAT PPSF/1.0
@SYSTEM
Sen uzman bir eczacı yapay zekâsısın.
@PATIENT
Parol ne işe yarar?
@TOOL_CALL
{
"name": "search_drug",
"arguments": {"drug": "Parol"}
}
@TOOL_RESPONSE
{"drug": "Parol", "active_ingredient": "Parasetamol", "usage": "Ağrı kesici ve ateş düşürücü"}
@PHARMACIST
```
---
## 🏛️ Mimari Tasarım Notları (PPSF v1.1 Desteği)
Hugging Face standart `messages` yapısında `thought` veya `reference` rolleri bulunmamaktadır. Bu nedenle PPSF formatında CoT (Düşünce Adımları) ve RAG (Referans Dokümanlar) desteği `metadata` nesnesi üzerinden sağlanmıştır:
```python
{
"role": "user",
"content": "Grip için hangi ilacı kullanmalıyım?",
"metadata": {
"reference": "[Kılavuz Doc #42]: Parasetamol 500mg tercih edilir."
}
}
```
Jinja2 şablonu bu `metadata` içeriğini otomatik olarak algılar ve `@REFERENCE` ile `@THOUGHT` bloklarını sırasıyla bağlama yerleştirir. Bu yaklaşım, ekosistem uyumluluğunu bozmadan formatı genişletilebilir kılar.
|