메인 콘텐츠로 건너뛰기
도구 호출을 사용하면 모델이 응답의 일부로 도구를 호출할 수 있도록 기능을 확장할 수 있습니다. 현재 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 키를 생성하세요
)

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)