Вызов функций (tools)
Как использовать function calling (tool use) в GetVibe API: параметры tools и tool_choice и многоходовой диалог с инструментами. Полный агентный цикл на Python и curl.
Вызов функций (tool use) позволяет модели запрашивать вызовы ваших функций и получать результат обратно. Поддерживается на всех моделях, совместимых с OpenAI.
Параметры
| Параметр | Тип | Описание |
|---|---|---|
tools | arrayGPT · Claude | Список инструментов. Каждый объект: { type: "function", function: { name, description, parameters } }. |
tool_choice | string | objectGPT · Claude | "auto" (модель решает сама), "none" (не вызывать), "required" (обязательно вызвать) или { type: "function", function: { name } } — конкретный инструмент. |
parallel_tool_calls | booleanGPT | true — модель запрашивает несколько инструментов сразу. По умолчанию true. Claude не поддерживает этот флаг, но выполняет параллельные вызовы самостоятельно. |
Пример: один вызов
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?"}]
}'Многоходовой режим: передача результата обратно
После вызова инструмента добавьте сообщение с ролью tool с результатом и отправьте следующий запрос.
# 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 принимаются в OpenAI-совместимой форме; их фактическая поддержка зависит от выбранной модели. Не рассчитывайте на побайтовую сквозную передачу или специфичные для апстрима поля ответа.