> ## Documentation Index
> Fetch the complete documentation index at: https://docs.wandb.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# 도구 호출

> Serverless Inference에서 함수 및 도구 호출을 사용해 모델이 생성 중 외부 도구와 API를 호출하도록 할 수 있습니다.

도구 호출은 모델의 기능을 확장하여 응답의 일부로 도구를 호출할 수 있게 합니다. 이를 통해 모델은 실시간 데이터를 가져오고, 애플리케이션에서 액션을 트리거하거나, 그 밖에 트레이닝 데이터의 범위를 넘어 요청을 처리할 수 있습니다. Serverless Inference는 함수 호출만 지원합니다.

함수를 호출하려면 모델에 보내는 요청에 함수와 해당 인수를 함께 지정하세요. 모델은 prompt에 응답하기 위해 함수를 실행할지 결정하고, 실행하는 경우 인수 값을 제공합니다.

다음 예시에서는 `get_weather` 함수를 정의하고, 이를 호출해야 답할 수 있는 질문을 모델에 전달합니다.

<Tabs>
  <Tab title="Python">
    ```python theme={null}
    import openai

    client = openai.OpenAI(
        base_url='https://api.inference.wandb.ai/v1',
        api_key="[YOUR-API-KEY]",  # https://wandb.ai/settings 에서 API 키를 생성하세요
    )

    response = client.chat.completions.create(
        model="openai/gpt-oss-20b",
        messages=[
            {"role": "user", "content": "What is the weather like in San Francisco? Use Fahrenheit."},
        ],
        tool_choice="auto",
        tools=[
            {
                "type": "function",
                "function": {
                    "name": "get_weather",
                    "description": "Get the current weather in a given location",
                    "parameters": {
                        "type": "object",
                        "properties": {
                            "location": {"type": "string", "description": "City and state, e.g., 'San Francisco, CA'"},
                            "unit": {"type": "string", "enum": ["celsius", "fahrenheit"]},
                        },
                        "required": ["location", "unit"],
                    },
                },
            }
        ],
    )

    print(response.choices[0].message.tool_calls)
    ```
  </Tab>

  <Tab title="Bash">
    ```bash theme={null}
    curl https://api.inference.wandb.ai/v1/chat/completions \
      -H "Content-Type: application/json" \
      -H "Authorization: Bearer [YOUR-API-KEY]" \
      -d '{
        "model": "openai/gpt-oss-20b",
            "messages": [
                {"role": "user", "content": "What is the weather like in San Francisco? Use Fahrenheit."},
            ],
            "tool_choice": "auto",
            "tools": [
                {
                    "type": "function",
                    "function": {
                        "name": "get_weather",
                        "description": "Get the current weather in a given location",
                        "parameters": {
                            "type": "object",
                            "properties": {
                                "location": {"type": "string", "description": "City and state, e.g., 'San Francisco, CA'"},
                                "unit": {"type": "string", "enum": ["celsius", "fahrenheit"]},
                            },
                            "required": ["location", "unit"],
                        },
                    },
                }
            ],
      }'
    ```
  </Tab>
</Tabs>
