🚀 土耳其語函數調用模型
本項目基於預訓練模型進行微調,得到了能夠執行土耳其語函數調用任務的模型。它以特定的基礎模型為起點,在相關數據集上進行訓練,藉助先進的庫和工具加速訓練過程,為土耳其語的函數調用任務提供了高效的解決方案。
🚀 快速開始
本模型改編自 ytu-ce-cosmos/Turkish-Llama-8b-DPO-v0.1,並在 atasoglu/turkish-function-calling-20k 數據集上進行微調,以執行土耳其語的函數調用任務。
- 開發者:atasoglu
- 許可證:apache - 2.0
- 微調基礎模型:ytu - ce - cosmos/Turkish - Llama - 8b - DPO - v0.1
這個 llama 模型使用 Unsloth 和 Huggingface 的 TRL 庫進行訓練,速度提升了 2 倍。

📦 安裝指南
此部分文檔未提及具體安裝步驟,若有需要可參考相關依賴庫的官方文檔進行安裝,如 unsloth
、transformers
等。
💻 使用示例
基礎用法
首先,加載模型:
import json
from unsloth import FastLanguageModel
model, tokenizer = FastLanguageModel.from_pretrained(
model_name="atasoglu/Turkish-Llama-3-8B-function-calling",
load_in_4bit=True,
)
FastLanguageModel.for_inference(model)
設置工具和消息:
system_prompt = """Sen yardımsever, akıllı ve fonksiyon çağrısı yapabilen bir asistansın.
Aşağıda JSON parçası içinde verilen fonksiyonları kullanarak kullanıcının sorusunu uygun şekilde cevaplamanı istiyorum.
Fonksiyon çağrısı yaparken uyman gereken talimatlar:
* Fonksiyonlar, JSON şeması olarak ifade edilmiştir.
* 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.
* Fonksiyonların parametreleri için asla uydurmalar yapma ve sadece kullanıcının verdiği bilgileri kullan.
* 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.
Bu talimatlara uyarak soruları cevaplandır."""
user_prompt = """### Fonksiyonlar
'''json
{tools}
'''
### Soru
{query}"""
tools = [
{
"type": "function",
"function": {
"name": "get_weather",
"description": "Get current temperature for a given location.",
"parameters": {
"type": "object",
"properties": {
"location": {
"type": "string",
"description": "City and country e.g. Bogotá, Colombia",
}
},
"required": ["location"],
"additionalProperties": False,
},
"strict": True,
},
}
]
query = "Paris'te hava şu anda nasıl?"
messages = [
{
"role": "system",
"content": system_prompt,
},
{
"role": "user",
"content": user_prompt.format(
tools=json.dumps(tools, ensure_ascii=False),
query=query,
),
},
]
⚠️ 重要提示
在運行前,將用戶提示中的單引號字符改為反引號以指定 JSON 片段。
然後,生成並評估輸出:
import re
def eval_function_calling(text):
match_ = re.search(r"```json(.*)```", text, re.DOTALL)
if match_ is None:
return False, text
return True, json.loads(match_.group(1).strip())
inputs = tokenizer.apply_chat_template(
messages,
add_generation_prompt=True,
return_dict=True,
return_tensors="pt",
).to("cuda")
generation_kwargs = dict(
do_sample=True,
use_cache=True,
max_new_tokens=500,
temperature=0.3,
top_p=0.9,
top_k=40,
)
outputs = model.generate(**inputs, **generation_kwargs)
output_ids = outputs[:, inputs["input_ids"].shape[1] :]
generated_texts = tokenizer.batch_decode(output_ids, skip_special_tokens=True)
has_function_calling, results = eval_function_calling(generated_texts[0])
if has_function_calling:
for result in results:
fn = result["function"]
name, args = fn["name"], fn["arguments"]
print(f"Calling {name!r} function with these arguments: {args}")
else:
print(f"No function call: {results!r}")
輸出示例:
Calling 'get_weather' function with these arguments: {"location":"Paris, France"}
📄 許可證
本模型使用的許可證為 apache - 2.0。