This project is a chatbot built using Chainlit, Google Gemini API, and GitHub OAuth authentication. Users must log in via GitHub to access the chatbot.
chatbot-authentication/
│
├── main.py # Core chatbot logic
├── .env # Environment variables (API keys, secrets)
├── chainlit.yaml # Chainlit config (OAuth settings)
└── README.md # Project documentation (this file)
uv init chatbot-authentication
cd chatbot-authentication
Make sure you have Python 3.10+
uv add chainlit python-dotenv google-generativeai
Add your Gemini API key, chainlit secret and GitHub OAuth credentials:
GEMINI_API_KEY=your_gemini_api_key
CHAINLIT_AUTH_SECRET...
# GitHub OAuth
OAUTH_GITHUB_CLIENT_ID=your_github_client_id
OAUTH_GITHUB_CLIENT_SECRET=your_github_client_secret
chainlit: 2.4.1
# Interface settings
ui:
name: "Chainlit Chatbot"
description: "A simple Question Answering Stateful chatbot with GitHub authentication built with Python, UV, and Chainlit."
# Message settings
default_expand_messages: true
# Auth settings
auth:
required: true
providers:
- github
# OAuth Configuration
oauth_providers:
github:
client_id: ${OAUTH_GITHUB_CLIENT_ID}
client_secret: ${OAUTH_GITHUB_CLIENT_SECRET}
chainlit run main.py -w
- 🔐 GitHub OAuth Login
- 💬 Stateful chat sessions
- 🧠 Responses generated using Gemini 2.0 API
- 👋 Friendly onboarding message
@cl.oauth_callback
def oauth_callback(...):
return default_user # Use GitHub user after login
@cl.on_chat_start
async def handle_chat_start():
cl.user_session.set("history", [])
@cl.on_message
async def handle_message(message):
# Append messages to history
# Use Gemini to generate response
# Send back the response
Created by Vikram.
Make sure .env
includes:
GEMINI_API_KEY=your_gemini_api_key (get from https://aistudio.google.com/apikey)
CHAINLIT_AUTH_SECRET...(cmd chainlit create-secret)
OAUTH_GITHUB_CLIENT_ID=...(get from github developers setting)
OAUTH_GITHUB_CLIENT_SECRET=...(get from github developers setting)