Bu doküman, tools'ların her LLM provider'a nasıl entegre edileceğini açıklar.
Tools'lar, AI'ın native function calling yeteneklerini kullanarak doğrudan fonksiyonları çağırmasına izin verir. Her provider'ın kendi function calling format'ı vardır, ancak biz OpenAI format'ını standart olarak kullanıyoruz ve provider'a göre dönüştürüyoruz.
export const TOOLS = {
calculate: {
name: 'calculate',
description: 'Performs mathematical calculations',
execute: async (args: { expression: string; precision?: number }) => {
// Tool implementation
},
},
// ... diğer tools
};function convertToolsToFunctionFormat() {
return [
{
type: 'function',
function: {
name: 'calculate',
description: 'Performs mathematical calculations',
parameters: {
type: 'object',
properties: {
expression: { type: 'string', description: 'Math expression' },
precision: { type: 'number', description: 'Decimal places' },
},
required: ['expression'],
},
},
},
// ... diğer tools
];
}Her provider'ın kendi function calling format'ı vardır:
- Format: OpenAI native format (direkt kullanılabilir)
- Parametre:
toolsvetool_choice - Örnek:
{
tools: [
{
type: 'function',
function: {
name: 'calculate',
description: '...',
parameters: { ... }
}
}
],
tool_choice: 'auto'
}- Format: Anthropic native format (dönüştürme gerekli)
- Parametre:
tools(array of tool objects) - Dönüşüm:
const anthropicTools = request.tools?.map(tool => ({
name: tool.function.name,
description: tool.function.description,
input_schema: tool.function.parameters,
}));- Format: Gemini native format (dönüştürme gerekli)
- Parametre:
tools(array withfunction_declarations) - Dönüşüm:
const geminiTools = request.tools ? [{
function_declarations: request.tools.map(tool => ({
name: tool.function.name,
description: tool.function.description,
parameters: tool.function.parameters,
})),
}] : undefined;- Format: OpenAI-compatible (direkt kullanılabilir)
- Parametre:
toolsvetool_choice - Not: Ollama'nın bazı modelleri function calling destekler
- Format: Model'e bağlı (çoğu model OpenAI format'ını destekler)
- Parametre: Model'e göre değişir
- Not: Qwen3-Omni gibi bazı modeller function calling destekler
async chat(request: LLMRequest): Promise<LLMResponse> {
const response = await fetch(`${baseURL}/chat/completions`, {
method: 'POST',
body: JSON.stringify({
model,
messages: request.messages,
temperature: request.temperature,
max_tokens: request.max_tokens,
// Tools direkt kullanılabilir
...(request.tools && { tools: request.tools }),
...(request.tool_choice && { tool_choice: request.tool_choice }),
}),
});
}async chat(request: LLMRequest): Promise<LLMResponse> {
// OpenAI format'ını Anthropic format'ına dönüştür
const anthropicTools = request.tools?.map(tool => ({
name: tool.function.name,
description: tool.function.description,
input_schema: tool.function.parameters,
}));
const response = await fetch(`${baseURL}/messages`, {
method: 'POST',
body: JSON.stringify({
model,
messages: request.messages,
temperature: request.temperature,
max_tokens: request.max_tokens,
// Anthropic format tools
...(anthropicTools && anthropicTools.length > 0 && { tools: anthropicTools }),
}),
});
}async chat(request: LLMRequest): Promise<LLMResponse> {
// OpenAI format'ını Gemini format'ına dönüştür
const geminiTools = request.tools ? [{
function_declarations: request.tools.map(tool => ({
name: tool.function.name,
description: tool.function.description,
parameters: tool.function.parameters,
})),
}] : undefined;
const response = await fetch(`${baseURL}/${model}:generateContent`, {
method: 'POST',
body: JSON.stringify({
contents: request.messages.map(msg => ({
role: msg.role === 'assistant' ? 'model' : 'user',
parts: [{ text: msg.content }],
})),
generationConfig: {
temperature: request.temperature,
maxOutputTokens: request.max_tokens,
},
// Gemini format tools
...(geminiTools && { tools: geminiTools }),
}),
});
}- LLMRequest interface'ini kontrol et:
toolsvetool_choiceparametreleri var mı? - Provider'ın function calling format'ını öğren: API dokümantasyonuna bak
- Format dönüşümü ekle: OpenAI format'ını provider format'ına çevir
- Test et: Tools'ların doğru çalıştığını doğrula
- ✅ OpenAI: Native function calling desteği eklendi
- ✅ Anthropic: Tools format dönüşümü eklendi
- ✅ Google: Tools format dönüşümü eklendi
⚠️ Ollama: Model'e bağlı (çoğu model destekler)⚠️ Hugging Face: Model'e bağlı (Qwen3-Omni destekler)⚠️ OpenRouter: OpenAI format'ını kullanır (direkt çalışır)⚠️ QrokCloud: OpenAI format'ını kullanır (direkt çalışır)⚠️ GitHub Copilot: OpenAI format'ını kullanır (direkt çalışır)
- Function Call Response Handling: AI'dan gelen function call'ları parse et ve execute et
- Multi-turn Function Calling: Birden fazla function call'ı handle et
- Tool Result Formatting: Tool sonuçlarını AI'ın anlayabileceği formata çevir
- Provider-specific Tool Limits: Her provider'ın tool limit'lerini handle et
- Tool Validation: Tool parametrelerini validate et