टूल कॉलिंग
टूल और फ़ंक्शन कॉलिंग
अपने फ़ंक्शन का वर्णन करें, और टूल का समर्थन करने वाला एक मॉडल आपको किसी एक को चलाने के लिए कहेगा। Oxyy डिक्लेरेशन को हर प्रोवाइडर की अपेक्षा के अनुसार ट्रांसलेट करता है, ताकि वही tools ऐरे OpenAI, Anthropic, Google, xAI और बाकी सभी पर काम करता है।
| पैरामीटर | टाइप | आवश्यक | विवरण |
|---|---|---|---|
| tools | array | वैकल्पिक | फ़ंक्शन घोषणाएँ: {type: "function", function: {name, description, parameters}}, जहाँ parameters एक JSON Schema ऑब्जेक्ट है। |
| tool_choice | string|object | वैकल्पिक | मॉडल कितनी स्वतंत्र रूप से किसी टूल को कॉल कर सकता है। इनमें से एक:noneautorequired{type:"function",function:{name}} डिफ़ॉल्ट auto |
| parallel_tool_calls | boolean | वैकल्पिक | प्रति टर्न एक से अधिक टूल कॉल की अनुमति दें। डिफ़ॉल्ट true |
import json, os from openai import OpenAI client = OpenAI( api_key=os.environ["OXYY_API_KEY"], base_url="https://api.oxyy.ai/v1" ) tools = [{ "type": "function", "function": { "name": "get_weather", "description": "Current weather for a city.", "parameters": { "type": "object", "properties": {"city": {"type": "string"}}, "required": ["city"], }, }, }] messages = [{"role": "user", "content": "Weather in Dhaka?"}] response = client.chat.completions.create( model="gpt-5.5", messages=messages, tools=tools, tool_choice="auto" ) call = response.choices[0].message.tool_calls[0] args = json.loads(call.function.arguments) # Run the tool yourself, then send the result back as a tool message. messages.append(response.choices[0].message) messages.append({ "role": "tool", "tool_call_id": call.id, "content": json.dumps({"temp_c": 31, "sky": "humid"}), }) final = client.chat.completions.create(model="gpt-5.5", messages=messages, tools=tools) print(final.choices[0].message.content)
import OpenAI from 'openai'; const client = new OpenAI({ apiKey: process.env.OXYY_API_KEY, baseURL: 'https://api.oxyy.ai/v1' }); const tools = [{ type: 'function', function: { name: 'get_weather', description: 'Current weather for a city.', parameters: { type: 'object', properties: { city: { type: 'string' } }, required: ['city'], }, }, }]; const messages = [{ role: 'user', content: 'Weather in Dhaka?' }]; const res = await client.chat.completions.create({ model: 'gpt-5.5', messages, tools, tool_choice: 'auto', }); const call = res.choices[0].message.tool_calls[0]; const args = JSON.parse(call.function.arguments); messages.push(res.choices[0].message, { role: 'tool', tool_call_id: call.id, content: JSON.stringify({ temp_c: 31, sky: 'humid' }), }); const final = await client.chat.completions.create({ model: 'gpt-5.5', messages, tools }); console.log(final.choices[0].message.content);
Tool-call turn
प्रतिक्रिया
{
"id": "chatcmpl-abc123",
"object": "chat.completion",
"created": 1700000000,
"model": "gpt-5.5",
"choices": [
{
"index": 0,
"message": {
"role": "assistant",
"content": null,
"tool_calls": [
{
"id": "call_abc123",
"type": "function",
"function": {
"name": "get_weather",
"arguments": "{\"city\":\"Dhaka\"}"
}
}
],
"refusal": null
},
"logprobs": null,
"finish_reason": "tool_calls"
}
],
"usage": { "prompt_tokens": 61, "completion_tokens": 18, "total_tokens": 79, "cost": 0.00029 }
}लूप। असिस्टेंट मैसेज जोड़ें जैसा कि यह वापस आया था, then one
{role:"tool", tool_call_id, content}हर कॉल पर मैसेज, और पूरी बातचीत दोबारा भेजें। finish_reason है tool_callsजब भी कॉल मौजूद हों, उन प्रदाताओं पर भी जो रिपोर्ट करते हैं stop. रीज़निंग मॉडल पर, वापस भेजें कोई भी reasoning_details बिना किसी बदलाव के ताकि मॉडल की अपनी सोच राउंड ट्रिप में सुरक्षित रहे।केवल फंक्शन टूल्स। Oxyy अपना कोई भी होस्टेड टूल नहीं चलाता है — सक्षम करने के लिए कोई वेब सर्च, कोड इंटरप्रेटर या फ़ाइल सर्च नहीं है। एक फ़ंक्शन घोषित करें और इसे अपने एप्लिकेशन में चलाएं। Anthropic के सर्वर टूल अपवाद हैं: उन्हें प्रदाता को बिना छुए अग्रेषित किया जाता है Anthropic SDK.
