Funktionsaufrufe (Tools)
So verwenden Sie Function Calling (Tool-Nutzung) mit der GetVibe API: die Parameter tools und tool_choice sowie eine mehrstufige Tool-Konversation. Vollständige Agentenschleife in Python und curl.
Mit Funktionsaufrufen (Tool-Nutzung) kann das Modell Aufrufe Ihrer Funktionen anfordern und das Ergebnis zurückerhalten. Unterstützt von allen OpenAI-kompatiblen Modellen.
Parameter
| Parameter | Typ | Beschreibung |
|---|---|---|
tools | arrayGPT · Claude | Liste der Tools. Jedes Objekt: { type: "function", function: { name, description, parameters } }. |
tool_choice | string | objectGPT · Claude | „auto“ (Modell entscheidet), „none“ (nicht aufrufen), „required“ (muss aufgerufen werden) oder { type: "function", function: { name } } — ein bestimmtes Tool. |
parallel_tool_calls | booleanGPT | true – das Modell fordert mehrere Tools gleichzeitig an. Standardmäßig true. Claude unterstützt dieses Flag nicht, führt parallele Aufrufe jedoch selbst aus. |
Beispiel: einzelner Aufruf
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?"}]
}'Mehrere Durchläufe: Ergebnis zurückübergeben
Fügen Sie nach dem Aufruf des Tools eine tool-Nachricht mit dem Ergebnis hinzu und senden Sie die nächste Anfrage.
# 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."Beispielantwort (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"
}]
}Die Felder
tools und tool_choice werden im OpenAI-kompatiblen Format akzeptiert; ihre tatsächliche Unterstützung hängt vom gewählten Modell ab. Verlassen Sie sich nicht auf eine bytegenaue Durchleitung oder upstream-spezifische Antwortfelder.