Skip to content

An API for attatching AI chatbots to systems without re-implementing logic every time.

Notifications You must be signed in to change notification settings

RLucasLR/ai-api

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Lucas AI Integration API

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.

Features

  • 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.

Tech Stack

  • 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.

Getting Started

Prerequisites

  • Python 3.13+
  • A Google Gemini API Key

Installation

  1. Clone the repository:

    git clone https://github.com/RLucasLR/ai-api.git
    cd ai-api
  2. Create and activate a virtual environment:

    python -m venv .venv
    source .venv/bin/activate  # On Windows: .venv\Scripts\activate
  3. Install dependencies:

    pip install -r requirements.txt
  4. Set up environment variables in a .env file:

    GOOGLE_API_KEY=your_gemini_api_key
    PORTFOLIO_CHAT_API_KEY=your_custom_api_key_for_accessing_this_api

Database Initialization

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.py

Running the API

python main.py

The API will be available at http://127.0.0.1:5000.

API Documentation

POST /portfolio-chat

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..."
}

Project Structure

  • 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.

About

An API for attatching AI chatbots to systems without re-implementing logic every time.

Resources

Stars

Watchers

Forks