메인 콘텐츠로 건너뛰기
도구 호출을 사용하면 모델의 응답에 도구 호출을 포함시켜 모델의 기능을 확장할 수 있습니다. 현재 W&B Inference는 함수 호출만 지원합니다. 함수를 호출하려면 요청에 함수와 해당 인자를 함께 지정해야 합니다. 모델은 요청을 충족하기 위해 해당 함수를 실행해야 하는지 여부를 결정하고, 필요하다면 함수의 인자 값을 지정합니다.
import openai

client = openai.OpenAI(
    base_url='https://api.inference.wandb.ai/v1',
    api_key="<your-api-key>",  # https://wandb.ai/settings 에서 API key를 생성하세요
)

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)