Skip to content

Function Calling

Medium — good to knowAI & ML

ELI5 — The Vibe Check

Function Calling is the OpenAI term for what Anthropic calls Tool Use — teaching the AI to call your code functions. You tell the AI 'here are functions you can use' with their names and parameters, and the AI decides which to call and with what arguments. Your code executes the function and tells the AI the result. It's AI and your code collaborating.

Real Talk

Function calling is the mechanism by which LLMs generate structured JSON specifying a function name and arguments for the host application to execute. The model determines when and how to call a function based on the user's request and the function's description. Results are fed back to the model as tool results. Standardized across OpenAI, Anthropic, Google, and others.

Show Me The Code

response = client.chat.completions.create(
    model="gpt-4",
    messages=[{"role": "user", "content": "What's the weather in Paris?"}],
    functions=[{
        "name": "get_weather",
        "parameters": {
            "type": "object",
            "properties": {"city": {"type": "string"}},
            "required": ["city"]
        }
    }]
)

When You'll Hear This

"Use function calling to let the AI query the database." / "Function calling is OpenAI's name for tool use."

Made with passive-aggressive love by manoga.digital. Powered by Claude.