메인 콘텐츠로 건너뛰기
Tool calling 을 사용하면 모델의 응답 과정에서 툴을 호출하도록 기능을 확장할 수 있습니다. 현재 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)