How wengxiaoxiong/function-calling-demo works
Main Components
a) Client Layer:
• Main Application (main.py)
• Chat Handler (chat.py)
b) Function Management Layer:
• Tools Registry (tools.py)
• Function Implementations (functions.py)
c) External Services:
• OpenAI API
• Weather Data Service (mock)
Component Relationships
[User] → [Main Application] → [Chat Handler] ↔ [OpenAI API]
• ↓
• [Tools Registry]
• ↓
• [Function Implementations]
• ↓
• [Weather Data Service (Mock)]
Component Details
Main Application (main.py):
• Entry point for the application
• Orchestrates the flow between user input and chat handling
Chat Handler (chat.py):
• Manages OpenAI API communication
• Implements retry logic
• Processes chat completions
Tools Registry (tools.py):
• Defines available functions for the LLM
• Manages function specifications
• Routes function calls to implementations
Function Implementations (functions.py):
• Contains mock weather data functions
• Implements business logic for tools
Additional Elements
• Flow numbers
A title: "Function Calling Demo - System Architecture"
Technical Details to Note
• Python environment boundary
• .env configuration for API keys
• Mock components vs real services
• Error handling/retry paths