Skip to content

Tool use (function calling)#

Same OpenAI shape. Define tools as JSON Schema; the model calls a function when appropriate, you execute it and return the result.

tools = [{
    "type": "function",
    "function": {
        "name": "get_weather",
        "description": "Current weather in a Swiss city.",
        "parameters": {
            "type": "object",
            "properties": {
                "city": {"type": "string", "description": "City name"},
            },
            "required": ["city"],
        },
    },
}]

resp = client.chat.completions.create(
    model="siati/llama-3.1-405b",
    messages=[{"role": "user", "content": "What's the weather in Lugano?"}],
    tools=tools,
)

# resp.choices[0].message.tool_calls contains the function called

Best for agentic workflows with real tools (DB queries, external APIs, calculations). For deterministic JSON output WITHOUT tools, see structured output.