An open API service indexing awesome lists of open source software.

https://github.com/motojinc25/wedx-chat-completion

Chat Completions engine with function calling, streaming, Semantic Kernel/Azure, and full observability
https://github.com/motojinc25/wedx-chat-completion

azure-openai chat-completion entra-id fastapi function-calling hawaii mcp observability opentelemetry oss postgresql python react semantic-kernel streaming typescript

Last synced: 27 days ago
JSON representation

Chat Completions engine with function calling, streaming, Semantic Kernel/Azure, and full observability

Awesome Lists containing this project

README

          

# ๐ŸŒบ WeDX Chat Completion


๐Ÿ๏ธ Aloha from Hawaii ๐Ÿ๏ธ


The open-core engine powering intelligent conversations

[![License](https://img.shields.io/badge/License-MIT-blue.svg)](https://opensource.org/licenses/MIT)
[![React](https://img.shields.io/badge/React-18+-blue.svg)](https://react.dev/)
[![FastAPI](https://img.shields.io/badge/FastAPI-0.104+-green.svg)](https://fastapi.tiangolo.com/)
[![TypeScript](https://img.shields.io/badge/TypeScript-5.0+-blue.svg)](https://www.typescriptlang.org/)
[![Python](https://img.shields.io/badge/Python-3.11+-blue.svg)](https://www.python.org/)

*Born under the Hawaiian sun, engineered for the world* ๐ŸŒด

---

## ๐ŸŒŠ Welcome to WeDX Chat Completion

Like the gentle trade winds of Hawaii, **WeDX Chat Completion** brings effortless conversational AI to your applications. This open-source platform provides OpenAI Chat Completion-compatible APIs with advanced function calling, real-time streaming, and enterprise-grade security.

**WeDX Chat Completion** serves as the open-core foundation that powers **[WeDX Chat Ci](https://wedx.cc)** โ€” our comprehensive commercial AI platform. While this OSS version provides core conversational AI capabilities, WeDX Chat Ci offers enhanced enterprise features, professional support, and managed cloud services.

Developed with the spirit of Hawaiian hospitality, our platform welcomes developers from around the world to build intelligent, interactive experiences.

## โœจ Key Features

### ๐Ÿค– **Intelligent Conversations**

- **OpenAI-Compatible API**: Seamless integration with existing Chat Completion workflows
- **Real-time Streaming**: Live response generation with function call detection
- **Microsoft Semantic Kernel**: Advanced AI orchestration with Azure OpenAI
- **Function Calling**: Math, Time, HTTP operations, and extensible MCP plugin support

### ๐Ÿ”’ **Enterprise Security**

- **Microsoft Entra ID**: Enterprise-grade authentication and authorization
- **JWT Token Validation**: Secure API access with automatic token verification
- **Audit Logging**: Comprehensive tracking of user actions and system events
- **Multi-mode Support**: Development, Production, and Demo modes

### ๐Ÿ—๏ธ **Modern Architecture**

- **Function-First Design**: Domain-driven architecture for scalability
- **Full-Stack TypeScript**: End-to-end type safety
- **PostgreSQL**: Robust database with automatic migrations
- **OpenTelemetry**: Complete observability with traces, logs, and metrics

### ๐ŸŽจ **Developer Experience**

- **React 18+ Frontend**: Modern UI with Shadcn/UI components
- **FastAPI Backend**: High-performance Python API server
- **Code Quality**: ESLint, Biome, and Ruff for consistent code standards

## ๐Ÿš€ Quick Start

### Prerequisites

- Node.js 18+ and pnpm
- Python 3.11+ and uv
- PostgreSQL 13+
- Azure OpenAI Service (for AI features)
- Microsoft Entra ID App Registration (for authentication)

### ๐Ÿƒโ€โ™‚๏ธ Get Running in 5 Minutes

```bash
# 1. Clone the repository
git clone https://github.com/motojinc25/wedx-chat-completion.git
cd wedx-chat-completion

# 2. Install dependencies
cd frontend && pnpm install
cd ../backend && uv sync

# 3. Set up environment variables
cp frontend/.env.example frontend/.env
cp backend/.env.example backend/.env
# Edit .env files with your configurations

# 4. Initialize database
cd backend && uv run alembic upgrade head

# 5. Start both services
cd frontend && pnpm run dev:full
```

Your services will be running at:
- **Frontend**: http://localhost:5173
- **Backend API**: http://localhost:8000
- **API Docs**: http://localhost:8000/docs

## ๐Ÿ—๏ธ Architecture Overview

WeDX Chat Completion follows a **Function-First** architecture, organizing code by business capabilities rather than technical layers.

### Frontend Structure

```
frontend/src/
โ”œโ”€โ”€ features/ # Business features
โ”‚ โ”œโ”€โ”€ administration/ # User & tenant management
โ”‚ โ”œโ”€โ”€ dashboard/ # Monitoring dashboards
โ”‚ โ”œโ”€โ”€ data-management/ # Master data & settings
โ”‚ โ”œโ”€โ”€ observability/ # Logs, traces, metrics
โ”‚ โ””โ”€โ”€ playground/ # Chat interface
โ”œโ”€โ”€ shared/ # Shared components
โ”‚ โ”œโ”€โ”€ components/ui/ # Shadcn/UI components
โ”‚ โ”œโ”€โ”€ contexts/ # React contexts
โ”‚ โ”œโ”€โ”€ hooks/ # Global hooks
โ”‚ โ””โ”€โ”€ utils/ # Utilities & API client
```

### Backend Structure

```
backend/
โ”œโ”€โ”€ features/ # Business features
โ”‚ โ”œโ”€โ”€ administration/ # User management APIs
โ”‚ โ”œโ”€โ”€ dashboard/ # System monitoring
โ”‚ โ”œโ”€โ”€ data_management/ # Configuration APIs
โ”‚ โ”œโ”€โ”€ observability/ # Telemetry endpoints
โ”‚ โ””โ”€โ”€ playground/ # Chat completion APIs
โ”œโ”€โ”€ shared/ # Shared infrastructure
โ”‚ โ”œโ”€โ”€ auth/ # Authentication & JIT provisioning
โ”‚ โ”œโ”€โ”€ database/ # PostgreSQL connection
โ”‚ โ”œโ”€โ”€ models/ # SQLAlchemy models
โ”‚ โ””โ”€โ”€ utils/ # Common utilities
```

## ๐Ÿ”ง Development Commands

### Frontend Development

```bash
cd frontend

# Development server
pnpm run dev # Start frontend only
pnpm run dev:full # Start both frontend & backend

# Build & Quality
pnpm run build # Production build
pnpm run check # Lint & format (Biome)
pnpm run test:run # Run tests once
pnpm run test # Test watch mode
```

### Backend Development

```bash
cd backend

# Development server
uv run python main.py # Start backend with logging

# Database
uv run alembic revision --autogenerate -m "Description"
uv run alembic upgrade head

# Quality & Testing
cd frontend && pnpm run check:backend # Lint & format (Ruff)
cd frontend && pnpm run test:backend # Run pytest tests
```

## ๐ŸŒ API Usage

### Chat Completion Endpoint

```bash
curl -X POST "http://localhost:8000/api/ai/chat/completion" \
-H "Content-Type: application/json" \
-H "Authorization: Bearer YOUR_TOKEN" \
-d '{
"messages": [
{"role": "user", "content": "Calculate 15 + 27"}
],
"system_message": "You are a helpful assistant."
}'
```

### Function Calling Response

```json
{
"content": "I'll calculate that for you.",
"function_calls": [
{
"name": "Math-Add",
"arguments": {"value1": 15, "value2": 27},
"result": 42
}
],
"finish_reason": "tool_calls",
"role": "assistant"
}
```

## ๐Ÿ”Œ Plugin System

Extend functionality with plugins:

### Core Plugins (Built-in)

- **Math Plugin**: Mathematical calculations
- **Time Plugin**: Current time and date functions
- **HTTP Plugin**: Web requests and interactions

### MCP Plugins (External Tools)

- **Context7 Plugin**: Documentation resolver
- **Custom MCP Plugins**: Extensible external tool integration

## ๐Ÿ“Š Observability

Built-in comprehensive monitoring:

- **OpenTelemetry Integration**: Traces, logs, and metrics
- **PostgreSQL Storage**: Direct database storage for telemetry data
- **Semantic Kernel Telemetry**: AI operation monitoring
- **Audit Logging**: Complete user action tracking
- **Performance Metrics**: Response times and resource usage

## ๐Ÿงช Testing

### Frontend Testing (Vitest + RTL)

```bash
cd frontend
pnpm run test:run # Run all tests
pnpm run test:ui # Interactive test runner
pnpm run test # Watch mode
```

### Backend Testing (pytest)

```bash
cd frontend
pnpm run test:backend # Run all backend tests

# Direct pytest (from backend directory)
cd backend && uv run pytest -v
```

## ๐Ÿค Contributing

We welcome contributions with the spirit of Hawaiian aloha!

1. **Fork the repository**
2. **Create a feature branch**: `git checkout -b feature/amazing-feature`
3. **Follow our patterns**: Use Function-First architecture
4. **Test your changes**: Ensure all tests pass
5. **Submit a PR**: Include clear description and tests

### Development Guidelines

- Follow existing code patterns and architecture
- Add tests for new features
- Update documentation as needed
- Use conventional commit messages
- Ensure linting passes (`pnpm run check`)

## ๐Ÿ“ Environment Configuration

### Frontend (.env)

```bash
VITE_APP_MODE=development # development/production/demo
VITE_AZURE_CLIENT_ID=your-client-id-here
VITE_AZURE_TENANT_ID=your-tenant-id-here
VITE_REDIRECT_URI=http://localhost:5173
```

### Backend (.env)

```bash
APP_MODE=development # development/production/demo
AZURE_TENANT_ID=your-tenant-id-here
AZURE_CLIENT_ID=your-client-id-here
AZURE_API_CLIENT_ID=your-api-client-id-here

# Azure OpenAI (for AI features)
AZURE_OPENAI_API_KEY=your-api-key-here
AZURE_OPENAI_ENDPOINT=https://your-resource.openai.azure.com/
AZURE_OPENAI_CHAT_DEPLOYMENT=gpt-4

# PostgreSQL
DB_HOST=localhost
DB_PORT=5432
DB_NAME=admin_db
DB_USER=admin_user
DB_PASSWORD=admin_password
```

## ๐Ÿ† Technology Stack

### Frontend

- **React 18+** with TypeScript
- **Next.js** App Router pattern
- **Vite** for lightning-fast builds
- **Tailwind CSS** + **Shadcn/UI**
- **MSAL.js** for Microsoft authentication
- **Vitest** + **React Testing Library**

### Backend

- **FastAPI** for high-performance APIs
- **SQLAlchemy** async ORM + **Alembic** migrations
- **PostgreSQL** for robust data storage
- **Microsoft Semantic Kernel** for AI orchestration
- **OpenTelemetry** for comprehensive observability
- **pytest** for thorough testing

## ๐ŸŒบ The Hawaiian Connection

Developed with aloha in the beautiful islands of Hawaii, this project embodies the Hawaiian values of:

- **Ohana** (Family): Building a welcoming community of developers
- **Malama** (Care): Thoughtful, sustainable code practices
- **Pono** (Rightness): Ethical AI development and responsible technology
- **Aloha** (Love & Respect): Inclusive, collaborative development culture

Like the diverse ecosystem of Hawaii, our platform brings together various technologies in harmony to create something beautiful and functional.

## ๐Ÿ–๏ธ License

Licensed under the MIT License. See [LICENSE](LICENSE) for details.

## ๐Ÿค™ Acknowledgments

- **Microsoft** for Semantic Kernel and Azure OpenAI services
- **OpenAI** for inspiring our Chat Completion compatibility
- **The open-source community** for the amazing tools that make this possible
- **Hawaii** for providing the perfect environment to innovate and create

---


๐ŸŒด Mahalo for using WeDX Chat Completion! ๐ŸŒด


Made with aloha in Hawaii ๐Ÿ๏ธ

**[โญ Star us on GitHub](https://github.com/motojinc25/wedx-chat-completion)** โ€ข **[๐Ÿ› Report Issues](https://github.com/motojinc25/wedx-chat-completion/issues)**