← Back

Function Calling

AI Patterns Python OpenAI

Problem

Chatbots can answer questions, but they can't do things. They can't check your database, call an API, or perform calculations with real data. The OpenAI docs show the concept but lack practical examples.

Solution

Working examples of AI that takes action, not just talks.

  • Define functions in plain English
  • Let AI decide when to call which function
  • Execute safely with your code
  • Chain multiple functions in one request

Demo

Define a weather function and a database query function. Ask "What's the weather in cities where our top 5 customers are located?" Watch the AI query the database, call the weather API, and combine results.

Define functions
Watch tool calls

Run it

git clone https://github.com/freshveejay/openai-function-calling-demo
cd openai-function-calling-demo
pip install -r requirements.txt
export OPENAI_API_KEY=sk-...
python main.py