Example: Tool Use (Function Calling)
This directory contains the code for the Tool Use (Function Calling) guide.
Getting Started
TensorZero
We provide a simple TensorZero configuration with a weather_chatbot chat function that has access to a get_temperature tool.
Prerequisites
- Install Docker.
- Generate an API key for OpenAI (
OPENAI_API_KEY).
Setup
- Set the
OPENAI_API_KEYenvironment variable in your shell (not in your.envfile). - Launch the TensorZero Gateway with
docker compose up.
Running the Example
Python (OpenAI SDK)
- Install the Python dependencies. We recommend using
uv:uv sync - Run the example with
python openai_sdk.py.
Node / TypeScript (OpenAI SDK)
- Install the dependencies with
npm install. - Run the example with
npx tsx openai_sdk.ts.
HTTP (cURL)
- Run the example with
bash curl.sh.