# wengxiaoxiong/function-calling-demo architecture

> Architecture diagram of the GitHub repository wengxiaoxiong/function-calling-demo, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-01-02). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/wengxiaoxiong/function-calling-demo
- Repository: https://github.com/wengxiaoxiong/function-calling-demo

## Overview

##### 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

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Title
    title[Function Calling Demo - System Architecture]
    title:::title

    %% User
    User((User))

    %% Main Components
    MainApp[Main Application]:::core
    ChatHandler[Chat Handler]:::core
    ToolsRegistry[Tools Registry]:::tools
    FuncImpl[Function Implementations]:::tools

    %% External Services
    OpenAI[OpenAI API]:::external
    WeatherService[Weather Data Service]:::mock

    %% Relationships
    User --> |1. User Input| MainApp
    MainApp --> |2. Process Request| ChatHandler
    ChatHandler <--> |3. API Communication| OpenAI
    ChatHandler --> |4. Function Call Request| ToolsRegistry
    ToolsRegistry --> |5. Route Function Call| FuncImpl
    FuncImpl --> |6. Get Weather Data| WeatherService
    WeatherService --> |7. Return Data| FuncImpl
    FuncImpl --> |8. Return Result| ToolsRegistry
    ToolsRegistry --> |9. Process Result| ChatHandler
    ChatHandler --> |10. Format Response| MainApp
    MainApp --> |11. Display Result| User

    %% Click Events
    click MainApp "https://github.com/wengxiaoxiong/function-calling-demo/blob/main/main.py"
    click ChatHandler "https://github.com/wengxiaoxiong/function-calling-demo/blob/main/chat.py"
    click ToolsRegistry "https://github.com/wengxiaoxiong/function-calling-demo/blob/main/tools.py"
    click FuncImpl "https://github.com/wengxiaoxiong/function-calling-demo/blob/main/functions.py"

    %% Styles
    classDef core fill:#a8d1f0,stroke:#000
    classDef tools fill:#ffd700,stroke:#000
    classDef external fill:#90EE90,stroke:#000
    classDef mock fill:#d3d3d3,stroke:#000
    classDef title fill:none,stroke:none

    %% Legend
    subgraph Legend
        L1[Core Components]:::core
        L2[Tools Layer]:::tools
        L3[External Services]:::external
        L4[Mock Services]:::mock
    end
```
