Text Generation
Transformers
GGUF
English
Turkish
text-generation-inference
unsloth
llama
trl
sft
conversational
Instructions to use oncu/Turkish-Llama-3-8B-function-calling-GGUF with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use oncu/Turkish-Llama-3-8B-function-calling-GGUF with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="oncu/Turkish-Llama-3-8B-function-calling-GGUF") messages = [ {"role": "user", "content": "Who are you?"}, ] pipe(messages)# Load model directly from transformers import AutoModel model = AutoModel.from_pretrained("oncu/Turkish-Llama-3-8B-function-calling-GGUF", device_map="auto") - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- llama.cpp
How to use oncu/Turkish-Llama-3-8B-function-calling-GGUF with llama.cpp:
Install (macOS, Linux)
curl -LsSf https://llama.app/install.sh | sh # Start a local OpenAI-compatible server with a web UI: llama serve -hf oncu/Turkish-Llama-3-8B-function-calling-GGUF:Q4_K_M # Run inference directly in the terminal: llama cli -hf oncu/Turkish-Llama-3-8B-function-calling-GGUF:Q4_K_M
Install from WinGet (Windows)
winget install llama.cpp # Start a local OpenAI-compatible server with a web UI: llama serve -hf oncu/Turkish-Llama-3-8B-function-calling-GGUF:Q4_K_M # Run inference directly in the terminal: llama cli -hf oncu/Turkish-Llama-3-8B-function-calling-GGUF:Q4_K_M
Use pre-built binary
# Download pre-built binary from: # https://github.com/ggerganov/llama.cpp/releases # Start a local OpenAI-compatible server with a web UI: ./llama-server -hf oncu/Turkish-Llama-3-8B-function-calling-GGUF:Q4_K_M # Run inference directly in the terminal: ./llama-cli -hf oncu/Turkish-Llama-3-8B-function-calling-GGUF:Q4_K_M
Build from source code
git clone https://github.com/ggerganov/llama.cpp.git cd llama.cpp cmake -B build cmake --build build -j --target llama-server llama-cli # Start a local OpenAI-compatible server with a web UI: ./build/bin/llama-server -hf oncu/Turkish-Llama-3-8B-function-calling-GGUF:Q4_K_M # Run inference directly in the terminal: ./build/bin/llama-cli -hf oncu/Turkish-Llama-3-8B-function-calling-GGUF:Q4_K_M
Use Docker
docker model run hf.co/oncu/Turkish-Llama-3-8B-function-calling-GGUF:Q4_K_M
- LM Studio
- Jan
- vLLM
How to use oncu/Turkish-Llama-3-8B-function-calling-GGUF with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "oncu/Turkish-Llama-3-8B-function-calling-GGUF" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "oncu/Turkish-Llama-3-8B-function-calling-GGUF", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }'Use Docker
docker model run hf.co/oncu/Turkish-Llama-3-8B-function-calling-GGUF:Q4_K_M
- SGLang
How to use oncu/Turkish-Llama-3-8B-function-calling-GGUF 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 "oncu/Turkish-Llama-3-8B-function-calling-GGUF" \ --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": "oncu/Turkish-Llama-3-8B-function-calling-GGUF", "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 "oncu/Turkish-Llama-3-8B-function-calling-GGUF" \ --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": "oncu/Turkish-Llama-3-8B-function-calling-GGUF", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }' - Ollama
How to use oncu/Turkish-Llama-3-8B-function-calling-GGUF with Ollama:
ollama run hf.co/oncu/Turkish-Llama-3-8B-function-calling-GGUF:Q4_K_M
- Unsloth Desktop
- Docker Model Runner
How to use oncu/Turkish-Llama-3-8B-function-calling-GGUF with Docker Model Runner:
docker model run hf.co/oncu/Turkish-Llama-3-8B-function-calling-GGUF:Q4_K_M
- Lemonade
How to use oncu/Turkish-Llama-3-8B-function-calling-GGUF with Lemonade:
Pull the model
# Download Lemonade from https://lemonade-server.ai/ lemonade pull oncu/Turkish-Llama-3-8B-function-calling-GGUF:Q4_K_M
Run and chat with the model
lemonade run user.Turkish-Llama-3-8B-function-calling-GGUF-Q4_K_M
List all available models
lemonade list
- Atomic Chat
Upload folder using huggingface_hub
Browse files- .gitattributes +1 -0
- README.md +155 -79
- turkish-llama-3-8b-function-calling.q2_k.gguf +3 -0
.gitattributes
CHANGED
|
@@ -37,3 +37,4 @@ turkish-llama-3-8b-function-calling-q2_k.gguf filter=lfs diff=lfs merge=lfs -tex
|
|
| 37 |
turkish-llama-3-8b-function-calling-q3_k_l.gguf filter=lfs diff=lfs merge=lfs -text
|
| 38 |
turkish-llama-3-8b-function-calling-q4_k_s.gguf filter=lfs diff=lfs merge=lfs -text
|
| 39 |
turkish-llama-3-8b-function-calling-q3_k_s.gguf filter=lfs diff=lfs merge=lfs -text
|
|
|
|
|
|
| 37 |
turkish-llama-3-8b-function-calling-q3_k_l.gguf filter=lfs diff=lfs merge=lfs -text
|
| 38 |
turkish-llama-3-8b-function-calling-q4_k_s.gguf filter=lfs diff=lfs merge=lfs -text
|
| 39 |
turkish-llama-3-8b-function-calling-q3_k_s.gguf filter=lfs diff=lfs merge=lfs -text
|
| 40 |
+
turkish-llama-3-8b-function-calling.q2_k.gguf filter=lfs diff=lfs merge=lfs -text
|
README.md
CHANGED
|
@@ -1,12 +1,5 @@
|
|
| 1 |
---
|
| 2 |
-
base_model:
|
| 3 |
-
datasets:
|
| 4 |
-
- atasoglu/turkish-function-calling-20k
|
| 5 |
-
language:
|
| 6 |
-
- en
|
| 7 |
-
- tr
|
| 8 |
-
license: apache-2.0
|
| 9 |
-
pipeline_tag: text-generation
|
| 10 |
tags:
|
| 11 |
- text-generation-inference
|
| 12 |
- transformers
|
|
@@ -14,76 +7,159 @@ tags:
|
|
| 14 |
- llama
|
| 15 |
- trl
|
| 16 |
- sft
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
## ✅ Quantized Models Download List
|
| 26 |
-
|
| 27 |
-
### 🔍 Recommended Quantizations
|
| 28 |
-
- **✨ General CPU Use:** [`Q4_K_M`](https://huggingface.co/oncu/Turkish-Llama-3-8B-function-calling-GGUF/resolve/main/turkish-llama-3-8b-function-calling-q4_k_m.gguf) (Best balance of speed/quality)
|
| 29 |
-
- **📱 ARM Devices:** [`Q4_0`](https://huggingface.co/oncu/Turkish-Llama-3-8B-function-calling-GGUF/resolve/main/turkish-llama-3-8b-function-calling-q4_0.gguf) (Optimized for ARM CPUs)
|
| 30 |
-
- **🏆 Maximum Quality:** [`Q8_0`](https://huggingface.co/oncu/Turkish-Llama-3-8B-function-calling-GGUF/resolve/main/turkish-llama-3-8b-function-calling-q8_0.gguf) (Near-original quality)
|
| 31 |
-
|
| 32 |
-
### 📦 Full Quantization Options
|
| 33 |
-
| 🚀 Download | 🔢 Type | 📝 Notes |
|
| 34 |
-
|:---------|:-----|:------|
|
| 35 |
-
| [Download](https://huggingface.co/oncu/Turkish-Llama-3-8B-function-calling-GGUF/resolve/main/turkish-llama-3-8b-function-calling-q2_k.gguf) |  | Basic quantization |
|
| 36 |
-
| [Download](https://huggingface.co/oncu/Turkish-Llama-3-8B-function-calling-GGUF/resolve/main/turkish-llama-3-8b-function-calling-q3_k_s.gguf) |  | Small size |
|
| 37 |
-
| [Download](https://huggingface.co/oncu/Turkish-Llama-3-8B-function-calling-GGUF/resolve/main/turkish-llama-3-8b-function-calling-q3_k_m.gguf) |  | Balanced quality |
|
| 38 |
-
| [Download](https://huggingface.co/oncu/Turkish-Llama-3-8B-function-calling-GGUF/resolve/main/turkish-llama-3-8b-function-calling-q3_k_l.gguf) |  | Better quality |
|
| 39 |
-
| [Download](https://huggingface.co/oncu/Turkish-Llama-3-8B-function-calling-GGUF/resolve/main/turkish-llama-3-8b-function-calling-q4_0.gguf) |  | Fast on ARM |
|
| 40 |
-
| [Download](https://huggingface.co/oncu/Turkish-Llama-3-8B-function-calling-GGUF/resolve/main/turkish-llama-3-8b-function-calling-q4_k_s.gguf) |  | Fast, recommended |
|
| 41 |
-
| [Download](https://huggingface.co/oncu/Turkish-Llama-3-8B-function-calling-GGUF/resolve/main/turkish-llama-3-8b-function-calling-q4_k_m.gguf) |  ⭐ | Best balance |
|
| 42 |
-
| [Download](https://huggingface.co/oncu/Turkish-Llama-3-8B-function-calling-GGUF/resolve/main/turkish-llama-3-8b-function-calling-q5_0.gguf) |  | Good quality |
|
| 43 |
-
| [Download](https://huggingface.co/oncu/Turkish-Llama-3-8B-function-calling-GGUF/resolve/main/turkish-llama-3-8b-function-calling-q5_k_s.gguf) |  | Balanced |
|
| 44 |
-
| [Download](https://huggingface.co/oncu/Turkish-Llama-3-8B-function-calling-GGUF/resolve/main/turkish-llama-3-8b-function-calling-q5_k_m.gguf) |  | High quality |
|
| 45 |
-
| [Download](https://huggingface.co/oncu/Turkish-Llama-3-8B-function-calling-GGUF/resolve/main/turkish-llama-3-8b-function-calling-q6_k.gguf) |  🏆 | Very good quality |
|
| 46 |
-
| [Download](https://huggingface.co/oncu/Turkish-Llama-3-8B-function-calling-GGUF/resolve/main/turkish-llama-3-8b-function-calling-q8_0.gguf) |  ⚡ | Fast, best quality |
|
| 47 |
-
| [Download](https://huggingface.co/oncu/Turkish-Llama-3-8B-function-calling-GGUF/resolve/main/turkish-llama-3-8b-function-calling-f16.gguf) |  | Maximum accuracy |
|
| 48 |
-
|
| 49 |
-
💡 **Tip:** Use `F16` for maximum precision when quality is critical
|
| 50 |
-
|
| 51 |
-
|
| 52 |
-
---
|
| 53 |
-
# 🚀 Applications and Tools for Locally Quantized LLMs
|
| 54 |
-
## 🖥️ Desktop Applications
|
| 55 |
-
|
| 56 |
-
| Application | Description | Download Link |
|
| 57 |
-
|-----------------|----------------------------------------------------------------------------------------------|--------------------------------------------------------------------------------|
|
| 58 |
-
| **Llama.cpp** | A fast and efficient inference engine for GGUF models. | [GitHub Repository](https://github.com/ggml-org/llama.cpp) |
|
| 59 |
-
| **Ollama** | A streamlined solution for running LLMs locally. | [Website](https://ollama.com/) |
|
| 60 |
-
| **AnythingLLM** | An AI-powered knowledge management tool. | [GitHub Repository](https://github.com/Mintplex-Labs/anything-llm) |
|
| 61 |
-
| **Open WebUI** | A user-friendly web interface for running local LLMs. | [GitHub Repository](https://github.com/open-webui/open-webui) |
|
| 62 |
-
| **GPT4All** | A user-friendly desktop application supporting various LLMs, compatible with GGUF models. | [GitHub Repository](https://github.com/nomic-ai/gpt4all) |
|
| 63 |
-
| **LM Studio** | A desktop application designed to run and manage local LLMs, supporting GGUF format. | [Website](https://lmstudio.ai/) |
|
| 64 |
-
| **GPT4All Chat**| A chat application compatible with GGUF models for local, offline interactions. | [GitHub Repository](https://github.com/nomic-ai/gpt4all) |
|
| 65 |
-
|
| 66 |
-
---
|
| 67 |
-
|
| 68 |
-
## 📱 Mobile Applications
|
| 69 |
-
|
| 70 |
-
| Application | Description | Download Link |
|
| 71 |
-
|-------------------|----------------------------------------------------------------------------------------------|--------------------------------------------------------------------------------|
|
| 72 |
-
| **ChatterUI** | A simple and lightweight LLM app for mobile devices. | [GitHub Repository](https://github.com/Vali-98/ChatterUI) |
|
| 73 |
-
| **Maid** | Mobile Artificial Intelligence Distribution for running AI models on mobile devices. | [GitHub Repository](https://github.com/Mobile-Artificial-Intelligence/maid) |
|
| 74 |
-
| **PocketPal AI** | A mobile AI assistant powered by local models. | [GitHub Repository](https://github.com/a-ghorbani/pocketpal-ai) |
|
| 75 |
-
| **Layla** | A flexible platform for running various AI models on mobile devices. | [Website](https://www.layla-network.ai/) |
|
| 76 |
-
|
| 77 |
-
---
|
| 78 |
-
|
| 79 |
-
## 🎨 Image Generation Applications
|
| 80 |
-
|
| 81 |
-
| Application | Description | Download Link |
|
| 82 |
-
|-------------------------------------|----------------------------------------------------------------------------------------------|--------------------------------------------------------------------------------|
|
| 83 |
-
| **Stable Diffusion** | An open-source AI model for generating images from text. | [GitHub Repository](https://github.com/CompVis/stable-diffusion) |
|
| 84 |
-
| **Stable Diffusion WebUI** | A web application providing access to Stable Diffusion models via a browser interface. | [GitHub Repository](https://github.com/AUTOMATIC1111/stable-diffusion-webui) |
|
| 85 |
-
| **Local Dream** | Android Stable Diffusion with Snapdragon NPU acceleration. Also supports CPU inference. | [GitHub Repository](https://github.com/xororz/local-dream) |
|
| 86 |
-
| **Stable-Diffusion-Android (SDAI)** | An open-source AI art application for Android devices, enabling digital art creation. | [GitHub Repository](https://github.com/ShiftHackZ/Stable-Diffusion-Android) |
|
| 87 |
-
|
| 88 |
---
|
| 89 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
---
|
| 2 |
+
base_model: ytu-ce-cosmos/Turkish-Llama-8b-DPO-v0.1
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3 |
tags:
|
| 4 |
- text-generation-inference
|
| 5 |
- transformers
|
|
|
|
| 7 |
- llama
|
| 8 |
- trl
|
| 9 |
- sft
|
| 10 |
+
license: apache-2.0
|
| 11 |
+
language:
|
| 12 |
+
- en
|
| 13 |
+
- tr
|
| 14 |
+
datasets:
|
| 15 |
+
- atasoglu/turkish-function-calling-20k
|
| 16 |
+
pipeline_tag: text-generation
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 17 |
---
|
| 18 |
|
| 19 |
+
# Uploaded model
|
| 20 |
+
|
| 21 |
+
**This model was adapted from [ytu-ce-cosmos/Turkish-Llama-8b-DPO-v0.1](https://huggingface.co/ytu-ce-cosmos/Turkish-Llama-8b-DPO-v0.1) and fine-tuned on the [atasoglu/turkish-function-calling-20k](https://huggingface.co/datasets/atasoglu/turkish-function-calling-20k) dataset to perform function calling tasks in Turkish.**
|
| 22 |
+
|
| 23 |
+
- **Developed by:** atasoglu
|
| 24 |
+
- **License:** apache-2.0
|
| 25 |
+
- **Finetuned from model :** ytu-ce-cosmos/Turkish-Llama-8b-DPO-v0.1
|
| 26 |
+
|
| 27 |
+
This llama model was trained 2x faster with [Unsloth](https://github.com/unslothai/unsloth) and Huggingface's TRL library.
|
| 28 |
+
|
| 29 |
+
[<img src="https://raw.githubusercontent.com/unslothai/unsloth/main/images/unsloth%20made%20with%20love.png" width="200"/>](https://github.com/unslothai/unsloth)
|
| 30 |
+
|
| 31 |
+
# Usage
|
| 32 |
+
|
| 33 |
+
First, load the model:
|
| 34 |
+
|
| 35 |
+
```python
|
| 36 |
+
import json
|
| 37 |
+
from unsloth import FastLanguageModel
|
| 38 |
+
|
| 39 |
+
# loading the model and tokenizer
|
| 40 |
+
model, tokenizer = FastLanguageModel.from_pretrained(
|
| 41 |
+
model_name="atasoglu/Turkish-Llama-3-8B-function-calling",
|
| 42 |
+
load_in_4bit=True,
|
| 43 |
+
)
|
| 44 |
+
FastLanguageModel.for_inference(model)
|
| 45 |
+
```
|
| 46 |
+
|
| 47 |
+
Setup the tools and messages:
|
| 48 |
+
|
| 49 |
+
```python
|
| 50 |
+
# define the prompt templates
|
| 51 |
+
system_prompt = """Sen yardımsever, akıllı ve fonksiyon çağrısı yapabilen bir asistansın.
|
| 52 |
+
Aşağıda JSON parçası içinde verilen fonksiyonları kullanarak kullanıcının sorusunu uygun şekilde cevaplamanı istiyorum.
|
| 53 |
+
|
| 54 |
+
Fonksiyon çağrısı yaparken uyman gereken talimatlar:
|
| 55 |
+
|
| 56 |
+
* Fonksiyonlar, JSON şeması olarak ifade edilmiştir.
|
| 57 |
+
* Eğer kullanıcının sorusu, bu fonksiyonlardan en az biri kullanılarak cevaplanabiliyorsa; uygun bir fonksiyon çağrısını JSON parçası içinde oluştur.
|
| 58 |
+
* Fonksiyonların parametreleri için asla uydurmalar yapma ve sadece kullanıcının verdiği bilgileri kullan.
|
| 59 |
+
* Eğer kullanıcının sorusu herhangi bir fonksiyon ile cevaplanamıyorsa, sadece "Verilen fonksiyonlarla cevaplanamaz" metnini döndür ve başka bir açıklama yapma.
|
| 60 |
+
|
| 61 |
+
Bu talimatlara uyarak soruları cevaplandır."""
|
| 62 |
+
|
| 63 |
+
user_prompt = """### Fonksiyonlar
|
| 64 |
+
|
| 65 |
+
'''json
|
| 66 |
+
{tools}
|
| 67 |
+
'''
|
| 68 |
+
|
| 69 |
+
### Soru
|
| 70 |
+
|
| 71 |
+
{query}"""
|
| 72 |
+
|
| 73 |
+
# define the tools and messages
|
| 74 |
+
tools = [
|
| 75 |
+
{
|
| 76 |
+
"type": "function",
|
| 77 |
+
"function": {
|
| 78 |
+
"name": "get_weather",
|
| 79 |
+
"description": "Get current temperature for a given location.",
|
| 80 |
+
"parameters": {
|
| 81 |
+
"type": "object",
|
| 82 |
+
"properties": {
|
| 83 |
+
"location": {
|
| 84 |
+
"type": "string",
|
| 85 |
+
"description": "City and country e.g. Bogotá, Colombia",
|
| 86 |
+
}
|
| 87 |
+
},
|
| 88 |
+
"required": ["location"],
|
| 89 |
+
"additionalProperties": False,
|
| 90 |
+
},
|
| 91 |
+
"strict": True,
|
| 92 |
+
},
|
| 93 |
+
}
|
| 94 |
+
]
|
| 95 |
+
query = "Paris'te hava şu anda nasıl?"
|
| 96 |
+
messages = [
|
| 97 |
+
{
|
| 98 |
+
"role": "system",
|
| 99 |
+
"content": system_prompt,
|
| 100 |
+
},
|
| 101 |
+
{
|
| 102 |
+
"role": "user",
|
| 103 |
+
"content": user_prompt.format(
|
| 104 |
+
tools=json.dumps(tools, ensure_ascii=False),
|
| 105 |
+
query=query,
|
| 106 |
+
),
|
| 107 |
+
},
|
| 108 |
+
]
|
| 109 |
+
```
|
| 110 |
+
|
| 111 |
+
**NOTE:** Change the *single quote* character to a *backtick* in the user prompt before running to specify the JSON snippet.
|
| 112 |
+
|
| 113 |
+
Then, generate and evaluate the output:
|
| 114 |
+
|
| 115 |
+
```python
|
| 116 |
+
import re
|
| 117 |
+
|
| 118 |
+
|
| 119 |
+
# define an evaluation function
|
| 120 |
+
def eval_function_calling(text):
|
| 121 |
+
match_ = re.search(r"```json(.*)```", text, re.DOTALL)
|
| 122 |
+
if match_ is None:
|
| 123 |
+
return False, text
|
| 124 |
+
return True, json.loads(match_.group(1).strip())
|
| 125 |
+
|
| 126 |
+
|
| 127 |
+
# tokenize the inputs
|
| 128 |
+
inputs = tokenizer.apply_chat_template(
|
| 129 |
+
messages,
|
| 130 |
+
add_generation_prompt=True,
|
| 131 |
+
return_dict=True,
|
| 132 |
+
return_tensors="pt",
|
| 133 |
+
).to("cuda")
|
| 134 |
+
|
| 135 |
+
# define generation arguments
|
| 136 |
+
generation_kwargs = dict(
|
| 137 |
+
do_sample=True,
|
| 138 |
+
use_cache=True,
|
| 139 |
+
max_new_tokens=500,
|
| 140 |
+
temperature=0.3,
|
| 141 |
+
top_p=0.9,
|
| 142 |
+
top_k=40,
|
| 143 |
+
)
|
| 144 |
+
|
| 145 |
+
# finally, generate the output
|
| 146 |
+
outputs = model.generate(**inputs, **generation_kwargs)
|
| 147 |
+
output_ids = outputs[:, inputs["input_ids"].shape[1] :]
|
| 148 |
+
generated_texts = tokenizer.batch_decode(output_ids, skip_special_tokens=True)
|
| 149 |
+
has_function_calling, results = eval_function_calling(generated_texts[0])
|
| 150 |
+
|
| 151 |
+
# print the model response
|
| 152 |
+
if has_function_calling:
|
| 153 |
+
for result in results:
|
| 154 |
+
fn = result["function"]
|
| 155 |
+
name, args = fn["name"], fn["arguments"]
|
| 156 |
+
print(f"Calling {name!r} function with these arguments: {args}")
|
| 157 |
+
else:
|
| 158 |
+
print(f"No function call: {results!r}")
|
| 159 |
+
```
|
| 160 |
+
|
| 161 |
+
Output:
|
| 162 |
+
|
| 163 |
+
```console
|
| 164 |
+
Calling 'get_weather' function with these arguments: {"location":"Paris, France"}
|
| 165 |
+
```
|
turkish-llama-3-8b-function-calling.q2_k.gguf
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:4bb8b5f18ec03d3ca183a3a55ae8a5ae5599c6eed2a549315f4d8dcaf8f9a0c3
|
| 3 |
+
size 3179132352
|