Fonksiyon çağrıları
Modelin uygulamandan bir işlem istemesini ve sonucu sonraki yanıtta kullanmasını sağla.
Araç seçimini belirle
{
"tools": [
{
"type": "function",
"function": {
"name": "get_stock",
"description": "Ürünün stok miktarını getir.",
"parameters": {
"type": "object",
"properties": {
"sku": {
"type": "string"
}
},
"required": [
"sku"
]
}
}
}
],
"tool_choice": {
"type": "function",
"function": {
"name": "get_stock"
}
},
"parallel_tool_calls": false
}Chat Completions’ta kararı modele bırakmak için auto, çağrıyı kapatmak için none veya zorunlu seçim için fonksiyon adını gönder. Akıştaki argüman parçalarını JSON olarak çözmeden önce seçenek ve araç indeksine göre birleştir. Tamamlanan çağrıyı istemcinde çalıştır.
Responses ve Messages örnekleri
curl "https://kavren.dev/v1/responses" \
-H "Authorization: Bearer $KAVREN_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "deepseek-v4.1-flash-fast",
"input": "KB-01 klavyeden kaç adet var?",
"tools": [
{
"type": "function",
"name": "get_stock",
"description": "Ürünün stok miktarını getir.",
"parameters": {
"type": "object",
"properties": {
"sku": {
"type": "string"
}
},
"required": [
"sku"
]
}
}
],
"tool_choice": "auto",
"max_output_tokens": 128
}'curl "https://kavren.dev/v1/messages" \
-H "Authorization: Bearer $KAVREN_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "deepseek-v4.1-flash-fast",
"messages": [
{
"role": "user",
"content": "KB-01 klavyeden kaç adet var?"
}
],
"tools": [
{
"name": "get_stock",
"input_schema": {
"type": "object",
"properties": {
"sku": {
"type": "string"
}
},
"required": [
"sku"
]
}
}
],
"tool_choice": {
"type": "tool",
"name": "get_stock",
"disable_parallel_tool_use": true
},
"max_tokens": 128
}'Responses için sonraki input dizisine çağrıyı ve aynı call_id ile function_call_output öğesini ekle. Messages için asistanın tool_use bloğunu geçmişe ekle, ardından eşleşen tool_use_id değerini taşıyan tool_result bloğunu kullanıcı mesajı olarak gönder.
Fonksiyonu tanımla
curl "https://kavren.dev/v1/chat/completions" \
-H "Authorization: Bearer $KAVREN_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "deepseek-v4.1-flash-fast",
"messages": [
{
"role": "user",
"content": "KB-01 klavyeden kaç adet var?"
}
],
"tools": [
{
"type": "function",
"function": {
"name": "get_stock",
"description": "Ürünün stok miktarını getir.",
"parameters": {
"type": "object",
"properties": {
"sku": {
"type": "string"
}
},
"required": [
"sku"
]
}
}
}
],
"tool_choice": "auto"
}'Çağrıyı işle
{
"choices": [
{
"message": {
"role": "assistant",
"content": null,
"tool_calls": [
{
"id": "call_1",
"type": "function",
"function": {
"name": "get_stock",
"arguments": "{\"sku\":\"KB-01\"}"
}
}
]
},
"finish_reason": "tool_calls"
}
]
}Argüman metnini JSON olarak ayrıştır. Stok servisini çağırmadan önce fonksiyon adını ve ürün kodunu doğrula. Birden fazla çağrı gelirse her sonucu kendi çağrı kimliğiyle eşleştir.
Sonucu modele gönder
curl "https://kavren.dev/v1/chat/completions" \
-H "Authorization: Bearer $KAVREN_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "deepseek-v4.1-flash-fast",
"messages": [
{
"role": "user",
"content": "KB-01 klavyeden kaç adet var?"
},
{
"role": "assistant",
"content": null,
"tool_calls": [
{
"id": "call_1",
"type": "function",
"function": {
"name": "get_stock",
"arguments": "{\"sku\":\"KB-01\"}"
}
}
]
},
{
"role": "tool",
"tool_call_id": "call_1",
"content": "{\"available\":7}"
}
],
"tools": [
{
"type": "function",
"function": {
"name": "get_stock",
"description": "Ürünün stok miktarını getir.",
"parameters": {
"type": "object",
"properties": {
"sku": {
"type": "string"
}
},
"required": [
"sku"
]
}
}
}
]
}'İstemcinde modelden gelen gerçek asistan mesajını ve stok servisinin sonucunu geçmişe ekle. Kullanıcıya gösterilecek metni sonraki asistan mesajından oku.