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
| 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. | |