π Project Structure smart-faq-bot/ βββ app.py # Flask app with API endpoints βββ chains.py # LangChain Gemini integration βββ db.py # SQLite database functions βββ templates/ β βββ index.html # Simple HTML frontend βββ .env # Environment variables (example) βββ requirements.txt # Python dependencies βββ logs.db # SQLite DB (auto-created) π Setup Instructions
Create the project directory and files: bashmkdir smart-faq-bot cd smart-faq-bot mkdir templates
Copy all the code files from the artifacts above into their respective locations. Install dependencies: bashpip install -r requirements.txt
Get Google API Key:
Go to Google AI Studio Create a new API key Copy your actual API key and replace your_google_api_key_here in the .env file
Run the application: bashpython app.py
Open your browser:
Go to http://localhost:5000/ Start asking questions!
β Features Implemented Backend (Flask):
POST /ask - Accepts questions, gets Gemini responses, saves to DB GET /logs - Returns all Q&A history as JSON Proper error handling and validation Environment variable loading with python-dotenv
LangChain Integration:
Uses langchain-google-genai for Gemini Pro access System prompt for FAQ assistant behavior Temperature control for response consistency
Database (SQLite):
Auto-creates logs.db on first run Stores questions, answers, and timestamps Helper functions for database operations
Frontend:
Clean, responsive HTML interface Real-time question submission via fetch API Loading states and error handling Q&A history viewer with toggle functionality Enter key support for quick submission
π§ API Usage
Ask a question:
bashcurl -X POST http://localhost:5000/ask
-H "Content-Type: application/json"
-d '{"question": "What is artificial intelligence?"}'
Get logs:
bashcurl http://localhost:5000/logs
The system is production-ready with proper error handling, database logging, and a user-friendly interface. Just add your Google API key and you're ready to go!