Skip to content
afaqulislamPublic

About

Enterprise-grade conversational AI assistant powered by Chainlit, OpenAI Agents SDK, OAuth 2.0, and modern Python architecture.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

Β 

History

7 Commits

Folders and files

Repository files navigation

πŸ€– ChatAUI β€” Advanced Conversational AI Agent

ChatAUI Logo

An enterprise-grade, stateful conversational AI assistant built using Chainlit, OpenAI Agents SDK, and python-dotenv. Engineered with modern package management (UV) and robust OAuth security (Google & GitHub).

Python Version Chainlit OpenAI Agents SDK

UV Package Manager MIT License Hugging Face


πŸ“– Table of Contents

  1. Overview
  2. Key Features
  3. Architecture & Flow
  4. Tech Stack
  5. Getting Started (Local Setup)
  6. Project Structure
  7. Deployment (Hugging Face / Docker)
  8. License
  9. Author & Contact

🌟 Overview

ChatAUI is a production-ready conversational AI agent designed to act as an interactive resume and personal assistant for Afaq Ul Islam. It demonstrates how to leverage modern LLM engineering paradigms like tool calling (function calling), agentic state management, and interactive custom UI components in Python.

By integrating the state-of-the-art OpenAI Agents SDK with a sleek Chainlit frontend, ChatAUI delivers a fluid, token-streamed chat experience powered by flexible backend APIs (such as OpenRouter). The project is built for secure environments, leveraging OAuth 2.0 (Google and GitHub) for identity provider (IdP) authentication.


✨ Key Features

  • πŸ€– OpenAI Agents SDK Integration: Leverages declarative agent definitions and autonomous, multi-turn tool execution.
  • ⚑ Ultra-Fast Runtime with UV: Utilizes Astral's uv for lightning-fast Python dependency management, virtual environments, and reproducible builds.
  • πŸ”„ Real-Time Token Streaming: Streaming responses with sub-second time-to-first-token (TTFT).
  • πŸ” OAuth 2.0 Authentication: Built-in support for securing user sessions using GitHub and Google login providers.
  • πŸ’Ύ Session-Level Chat Memory: Remembers context across multi-turn queries using Chainlit's stateful user sessions.
  • 🎨 Custom React Elements: Injects custom loaders (like DottedLoader.jsx) directly into the chat stream to enhance UX during tool execution.
  • πŸ› οΈ Local Agentic Tools: Integrates native Python function tools (get_afaqulislam_data) that safely format and retrieve localized JSON information.

πŸ“ Architecture & Flow

The interaction between the user, frontend, agent orchestrator, and external API services is designed for performance and separation of concerns:

sequenceDiagram
    autonumber
    actor User as Chat User
    participant CL as Chainlit Frontend
    participant Agent as Agent Orchestrator (main.py)
    participant Tool as Python Function Tool (data.py)
    participant LLM as OpenRouter API

    User->>CL: Submit Query ("What are Afaq's skills?")
    CL->>Agent: Forward Message & History
    Agent->>CL: Mount Custom Loader (DottedLoader.jsx)
    Agent->>LLM: Evaluate Prompt & Tool Specs
    LLM-->>Agent: Suggest Tool Call: get_afaqulislam_data()
    Agent->>Tool: Execute function tool
    Tool-->>Agent: Return structured JSON profile data
    Agent->>LLM: Send Tool Output + History
    LLM-->>Agent: Return response stream (tokens)
    Agent->>CL: Unmount Loader & Stream response tokens
    CL-->>User: Display final response
Loading

🧱 Tech Stack

Category Technology Purpose
Language Python 3.11+ Main programming language
Frontend Chainlit Reactive chat UI & session state management
AI Orchestration OpenAI Agents SDK Agent structure, history tracking, and tool execution
Model Hosting OpenRouter / OpenAI API access to top LLMs (Gemini, Claude, GPT)
Package Manager uv (by Astral) Ultra-fast dependency resolution and virtual environments
Authentication OAuth 2.0 Google & GitHub Identity Providers
UI Components React (JSX) Custom loaders and UI layout modifications
Deployment Docker Containerized target platform

βš™οΈ Getting Started (Local Setup)

To set up and run the project locally, ensure you have Python 3.11+ installed. We recommend using UV for managing dependencies.

1. Install UV

macOS / Linux:

curl -LsSf https://astral.sh/uv/install.sh | sh

Windows (PowerShell):

powershell -ExecutionPolicy ByPass -c "irm https://astral.sh/uv/install.ps1 | iex"

2. Clone the Repository & Initialize Environment

git clone https://github.com/afaqulislam/chataui.git
cd chataui

Create and activate a virtual environment:

uv venv
# On Windows
.venv\Scripts\activate
# On macOS/Linux
source .venv/bin/activate

3. Install Dependencies

uv pip install -r pyproject.toml

(Alternatively, run uv sync if utilizing workspace features).

4. Configure Environment Variables

Create a .env file in the root folder:

OPENROUTER_API_KEY=your-openrouter-api-key
OPENROUTER_BASE_URL=https://openrouter.ai/api/v1
OPENROUTER_MODEL=your-chosen-model-name

# OAuth Configuration (Optional for local testing if auth is disabled in chainlit.yaml)
OAUTH_GITHUB_CLIENT_ID=your-github-client-id
OAUTH_GITHUB_CLIENT_SECRET=your-github-client-secret
OAUTH_GOOGLE_CLIENT_ID=your-google-client-id
OAUTH_GOOGLE_CLIENT_SECRET=your-google-client-secret

# Secret key for encrypting cookie sessions
CHAINLIT_AUTH_SECRET=your-chainlit-auth-secret
CHAINLIT_URL=your_chainlit_url_here

Tip: You can generate a random secure auth secret using: chainlit create-secret

5. Launch the Application πŸš€

chainlit run main.py -w

The application will start, typically exposing the server at http://localhost:8000. The -w flag enables hot reloading during development.


πŸ“‚ Project Structure

chataui-app/
β”œβ”€β”€ .venv/                  # Virtual environment
β”œβ”€β”€ public/                 # Static assets and custom components
β”‚   β”œβ”€β”€ elements/
β”‚   β”‚   └── DottedLoader.jsx# Custom React wave loader
β”‚   β”œβ”€β”€ avatar.png          # Chatbot assistant avatar
β”‚   β”œβ”€β”€ favicon.png         # Website favicon
β”‚   β”œβ”€β”€ logo_dark.png       # Dark theme application logo
β”‚   β”œβ”€β”€ logo_light.png      # Light theme application logo
β”‚   └── theme.json          # Theme custom styling configuration
β”œβ”€β”€ .env.example            # Template for environment configuration
β”œβ”€β”€ .gitignore
β”œβ”€β”€ LICENSE                 # MIT Open-source license
β”œβ”€β”€ README.md               # Professional documentation
β”œβ”€β”€ chainlit.md             # Welcome page shown on user login
β”œβ”€β”€ chainlit.yaml           # Global configurations and OAuth setup
β”œβ”€β”€ data.py                 # Structured resume & skills database
β”œβ”€β”€ instructions.py         # System prompt & instruction manual for the agent
β”œβ”€β”€ main.py                 # Main entrypoint initiating Chainlit hooks & AI Agents
β”œβ”€β”€ pyproject.toml          # Declarative metadata and dependencies
└── uv.lock                 # Pinned reproducible dependency lockfile

☁️ Deployment (Hugging Face / Docker)

This repository is optimized for Docker-based hosting platforms, specifically Hugging Face Spaces, which automatically provisions SSL certificates required for secure OAuth redirection.

Dockerfile Configuration

To build the Docker image, use the following Dockerfile structure:

FROM python:3.11-slim

WORKDIR /app

# Upgrade pip and install build dependencies
RUN pip install --no-cache-dir --upgrade pip

# Copy project files
COPY . .

# Install dependencies directly from pyproject.toml
RUN pip install --no-cache-dir .

EXPOSE 7860

# Launch Chainlit pointing to the Space port
CMD ["chainlit", "run", "main.py", "--host", "0.0.0.0", "--port", "7860"]

Production OAuth Integration

Ensure your OAuth callback URLs match the public domain of your deployment:

  • GitHub Callback: https://<your-space-name>.hf.space/auth/github/callback
  • Google Callback: https://<your-space-name>.hf.space/auth/google/callback

πŸ“„ License

This project is licensed under the MIT License - see the LICENSE file for details.


πŸ§‘β€πŸ’» Author & Contact

Afaq Ul Islam


Built with ❀️ utilizing the power of Python, Chainlit, and Agentic AI.

About

Enterprise-grade conversational AI assistant powered by Chainlit, OpenAI Agents SDK, OAuth 2.0, and modern Python architecture.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages