A sophisticated AI chatbot built with Streamlit, LangChain, and OpenAI's GPT models, featuring knowledge base integration.
- Intelligent Conversations: Powered by OpenAI's GPT models
- Knowledge Base Integration: Upload documents for the bot to reference when answering questions
- RAG (Retrieval-Augmented Generation): Provides more accurate, grounded responses based on your documents
- Multiple Document Formats: Support for PDF, TXT, CSV, and DOCX files
- Adjustable Personalities: Choose between Helpful Assistant, Friendly Teacher, Creative Writer, or Technical Expert
- Multiple Models: Select between GPT-3.5-turbo and GPT-4o
- Conversation Memory: Chatbot remembers the context of your conversation
- Chat History Management: Save and load previous conversations
- Fallback Mode: Continues to function with basic responses when API is unavailable
- Responsive Design: Works on desktop and mobile devices
-
Clone this repository:
git clone https://github.com/your-username/ai-chatbot.git cd ai-chatbot -
Create a virtual environment (recommended):
python -m venv venv source venv/bin/activate # On Windows: venv\Scripts\activate -
Install required packages:
pip install -r requirements.txt -
Create a
.envfile in the project root and add your OpenAI API key:OPENAI_API_KEY=your_openai_api_key_here
-
Run the app:
streamlit run app.py -
Open your browser and navigate to
http://localhost:8501 -
Start chatting with your AI assistant!
- In the sidebar, under "Knowledge Base," click "Browse files" to select documents
- Upload PDFs, TXT files, CSVs, or DOCX documents that contain information you want the bot to reference
- Click "Process Documents" to analyze and embed the documents
- Once processed, the bot will automatically use these documents to provide more accurate answers
- You can clear the knowledge base at any time using the "Clear Knowledge Base" button
You can choose between different OpenAI models:
- GPT-3.5-turbo (default, uses less API quota)
- GPT-4o (more powerful but uses more API quota)
Adjust the chatbot's personality:
- Helpful Assistant: Provides clear and concise answers
- Friendly Teacher: Explains concepts in simple terms with examples
- Creative Writer: Helps with creative and engaging content
- Technical Expert: Provides detailed technical information with precise terminology
- Python 3.8+
- Streamlit
- LangChain
- OpenAI API key
- dotenv
- FAISS for vector storage
- Document processing libraries (pypdf, docx2txt)
See requirements.txt for complete dependencies.
For knowledge base functionality, install:
pip install langchain-openai faiss-cpu pypdf docx2txt
app.py: Main application code.env: Environment variables (API keys)requirements.txt: Required Python packagesuploaded_docs/: Directory where uploaded documents are temporarily storedchat_history_*.json: Saved chat history files
- The RAG implementation uses OpenAI Embeddings and FAISS for vector search
- Documents are split into chunks of 1000 characters with 200 character overlap for better retrieval
- The top 3 most relevant document chunks are retrieved for each user query
MIT License
- Streamlit for the wonderful web framework
- LangChain for the conversation management and RAG capabilities
- OpenAI for the GPT models and embeddings
- FAISS for efficient vector similarity search
Created with ❤️ by Ardavan
