テーマ
言語

関数呼び出し(ツール)

GetVibe API で function calling(ツール使用)を使う方法:tools および tool_choice パラメータと、マルチターンのツール会話。Python と curl による完全なエージェントループ。

関数呼び出し(ツール使用)により、モデルはユーザーの関数の呼び出しを要求し、その結果を受け取ることができます。すべてのOpenAI互換モデルでサポートされています。

パラメーター

パラメータータイプ説明
toolsarrayGPT · Claudeツールの一覧。各オブジェクト: { type: "function", function: { name, description, parameters } }。
tool_choicestring | objectGPT · Claude"auto"(モデルが判断)、"none"(呼び出さない)、"required"(必ず呼び出す)、または { type: "function", function: { name } }(特定のツール)。
parallel_tool_callsbooleanGPTtrue — モデルが複数のツールを同時に要求します。デフォルトは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 互換の形式で受け付けられますが、実際の対応状況は選択したモデルによります。バイト単位のパススルーやアップストリーム固有のレスポンスフィールドには依存しないでください。
GetVibe API の関数呼び出し — tools、tool_choice、Python の例 | GetVibe API