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).
- Overview
- Key Features
- Architecture & Flow
- Tech Stack
- Getting Started (Local Setup)
- Project Structure
- Deployment (Hugging Face / Docker)
- License
- Author & Contact
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.
- π€ OpenAI Agents SDK Integration: Leverages declarative agent definitions and autonomous, multi-turn tool execution.
- β‘ Ultra-Fast Runtime with UV: Utilizes Astral's
uvfor 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.
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
| 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 |
To set up and run the project locally, ensure you have Python 3.11+ installed. We recommend using UV for managing dependencies.
macOS / Linux:
curl -LsSf https://astral.sh/uv/install.sh | shWindows (PowerShell):
powershell -ExecutionPolicy ByPass -c "irm https://astral.sh/uv/install.ps1 | iex"git clone https://github.com/afaqulislam/chataui.git
cd chatauiCreate and activate a virtual environment:
uv venv
# On Windows
.venv\Scripts\activate
# On macOS/Linux
source .venv/bin/activateuv pip install -r pyproject.toml(Alternatively, run uv sync if utilizing workspace features).
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
chainlit run main.py -wThe application will start, typically exposing the server at http://localhost:8000. The -w flag enables hot reloading during development.
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
This repository is optimized for Docker-based hosting platforms, specifically Hugging Face Spaces, which automatically provisions SSL certificates required for secure OAuth redirection.
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"]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
This project is licensed under the MIT License - see the LICENSE file for details.
Afaq Ul Islam
- Role: Frontend Developer | SEO Specialist | Agentic AI Developer
- Website: https://afaqulislam.github.io
- LinkedIn: linkedin.com/in/afaqulislam
- GitHub: github.com/afaqulislam
- Email: afaqulislam707@gmail.com
Built with β€οΈ utilizing the power of Python, Chainlit, and Agentic AI.
