A central API for attaching AI chatbots to Lucas’s systems without re-implementing logic every time. This project centralizes AI chatbot infrastructure across multiple projects, allowing systems to connect and inherit a shared configuration.
- Centralized API key management: Manage access to AI services in one place.
- Model selection and version control: Consistent AI behavior across all attached systems.
- Shared RAG (Retrieval-Augmented Generation) pipelines: Uses a shared knowledge store for contextual responses.
- Consistent request and response formats: Simplifies integration for various front-end and back-end systems.
- Python (Flask): Backend API framework.
- Google Gemini API: Powering the AI responses and embeddings.
- SQLite: Stores knowledge chunks and their corresponding embeddings for RAG.
- Tailwind CSS: Used for the minimal landing page.
- Python 3.13+
- A Google Gemini API Key
-
Clone the repository:
git clone https://github.com/RLucasLR/ai-api.git cd ai-api -
Create and activate a virtual environment:
python -m venv .venv source .venv/bin/activate # On Windows: .venv\Scripts\activate
-
Install dependencies:
pip install -r requirements.txt
-
Set up environment variables in a
.envfile:GOOGLE_API_KEY=your_gemini_api_key PORTFOLIO_CHAT_API_KEY=your_custom_api_key_for_accessing_this_api
The project uses a SQLite database (rag.db) to store embeddings. The table is automatically created when you run main.py. To populate it with data, you can use the embedding script.
Note: Before running the script, ensure you have the correct source file you want to chunk. You can change the target file by modifying the SOURCE_FILE constant at the top of scripts/embedding.py.
python scripts/embedding.pypython main.pyThe API will be available at http://127.0.0.1:5000.
Interact with the AI assistant.
Request Body:
{
"api_key": "your_portfolio_chat_api_key",
"prompt": "Hello, who are you?",
"previous_chats": [
{"role": "user", "content": "Hi"},
{"role": "model", "content": "Hello! I am Lucas's AI assistant."}
]
}Response:
{
"chat": "I am an AI assistant embedded on the personal portfolio website of Lucas Reddington..."
}main.py: Entry point of the Flask application and API routes.services/ai.py: Core AI logic, RAG implementation, and Gemini integration.scripts/embedding.py: Script for generating and storing embeddings in the database.templates/: HTML templates for the landing page and testing.rag.db: SQLite database for storing portfolio information and embeddings.