फ़ंक्शन कॉलिंग (टूल्स)

GetVibe API के साथ function calling (tool use) कैसे उपयोग करें: tools और tool_choice parameters तथा multi-turn tool conversation। Python और curl में पूरा agent loop।

Function calling (tool use) से model आपके functions को calls का अनुरोध कर सकता है और result वापस पा सकता है। सभी OpenAI-compatible models पर supported है।

Parameters

ParameterTypeविवरण
toolsarrayGPT · Claudetools की सूची। प्रत्येक object: { type: "function", function: { name, description, parameters } }।
tool_choicestring | objectGPT · Claude"auto" (model तय करता है), "none" (call न करें), "required" (call करना ज़रूरी है), या { type: "function", function: { name } } — कोई विशिष्ट tool।
parallel_tool_callsbooleanGPTtrue — model एक साथ कई tools की request करता है। Default true। Claude इस flag को सपोर्ट नहीं करता, लेकिन parallel calls ख़ुद करता है।

उदाहरण: एकल कॉल

curl https://getvibeapi.com/v1/chat/completions \
  -H "Authorization: Bearer $GETVIBE_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "gpt-6.1-sol",
    "tools": [{
      "type": "function",
      "function": {
        "name": "get_weather",
        "description": "Returns the current weather in a city",
        "parameters": {
          "type": "object",
          "properties": {
            "city": { "type": "string", "description": "City name" }
          },
          "required": ["city"]
        }
      }
    }],
    "tool_choice": "auto",
    "messages": [{"role": "user", "content": "What is the weather in London?"}]
  }'

Multi-turn: परिणाम वापस भेजना

Tool call होने के बाद result के साथ एक tool role message जोड़ें और अगली request भेजें।

# messages after the first response with tool_call:
messages = [
    {"role": "user", "content": "What is the weather in London?"},
    # model response with the tool call
    {"role": "assistant", "tool_calls": msg.tool_calls, "content": None},
    # the result of your function
    {
        "role": "tool",
        "tool_call_id": msg.tool_calls[0].id,
        "content": json.dumps({"city": "London", "temp": 18, "desc": "Cloudy"}),
    },
]
resp2 = client.chat.completions.create(model="gpt-6.1-sol", tools=tools, messages=messages)
print(resp2.choices[0].message.content)
# → "It is currently 18°C and cloudy in London."

प्रतिक्रिया उदाहरण (tool_call)

{
  "choices": [{
    "message": {
      "role": "assistant",
      "content": null,
      "tool_calls": [{
        "id": "call_abc123",
        "type": "function",
        "function": {
          "name": "get_weather",
          "arguments": "{\"city\":\"London\"}"
        }
      }]
    },
    "finish_reason": "tool_calls"
  }]
}
tools और tool_choice fields OpenAI-compatible रूप में स्वीकार किए जाते हैं; उनका वास्तविक समर्थन चुने गए model पर निर्भर करता है। byte-for-byte pass-through या upstream-specific response fields पर भरोसा न करें।
GetVibe API function calling — tools, tool_choice, Python उदाहरण | GetVibe API