Python Function Calling Demo
OpenAI Function Calling Example Code#
Basic Setup#
Install Dependencies#
Initialize the Client#
Weather Lookup Implementation#
Mock Weather Function#
Main Conversation Function#
Key Features#
Supports multi-turn conversations
Automated function calling
Formatted result handling
Notes#
The API key must be set correctly
Make sure the network connection is stable
Be aware of API rate limits
Handle possible JSON parsing errors
Last verified/modified: 2026-09-28 (Base URL changed to api.crazyrouter.com; example model gpt-4o → gpt-5.5; examples not run live)
Modified at 2026-09-28 12:56:20