Skip to content

BorjaOteroFerreira/IALab-Suite

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

πŸ€– IALab-Suite

A complete AI tools suite with React interface and Flask backend for testing Large Language Models (LLM) using llama.cpp

License: MIT Python React Flask

πŸ“‹ Table of Contents

πŸš€ Features

🌟 Main Features

  • πŸ”’ Total Privacy: Works completely offline, without sending data to third parties
  • 🎨 Modern Interface: Responsive React frontend with modern design
  • πŸ”Œ Modular Architecture: Auto-discoverable tool system with dynamic registration
  • ⚑ Real Time: Bidirectional communication with WebSockets
  • 🧠 Multiple Models: Support for any GGUF model
  • πŸ“š Integrated RAG: Retrieval Augmented Generation system included
  • πŸ› οΈ AI Tools: Complete set of tools for the assistant with automatic discovery

🎯 Integrated Tools

  • πŸ” Internet Search: Serper API integration
  • πŸ”Ž Advanced Search: Specialized searches with Google dorks
  • πŸŽ₯ Video Search: YouTube API integration
  • πŸ’° Cryptocurrency Prices: Real-time information
  • πŸ–ΌοΈ Image Generation: AI image generation tool with Gradle API integration
  • 🌐 IP Information: Geographic data retrieval

πŸ—οΈ Architecture

IALab-Suite/
β”œβ”€β”€ πŸ–₯️ Frontend-React/          # Modern user interface
β”œβ”€β”€ πŸ”§ Backend-API/             # Flask API with WebSockets
β”œβ”€β”€ πŸ› οΈ tools/                  # Modular tools
└── πŸ“ chats/                  # Conversation storage

πŸ”§ Main Components

  • 🧠 Cortex: AI-powered tool processing engine
  • πŸ€– Assistant: Main AI assistant logic
  • πŸ” RAG: Retrieval Augmented Generation system
  • 🌐 API React: Flask server serving the React frontend
  • πŸ“‘ SocketIO: Real-time communication
  • πŸ› οΈ ToolRegistry: Automatic tool discovery and registration system

πŸ“¦ Installation

πŸ“‹ Prerequisites

  • Python 3.8+
  • Node.js 16+
  • npm or yarn
  • Git

πŸ› οΈ Step-by-Step Installation

1. πŸ“₯ Clone the Repository

git clone https://github.com/your-username/IALab-Suite.git
cd IALab-Suite

2. 🐍 Set up Python Environment

# Create virtual environment
python -m venv venv

# Activate virtual environment
# Windows
venv\Scripts\activate
# macOS/Linux
source venv/bin/activate

# Install Python dependencies
pip install -r requirements.txt

3. βš™οΈ Install llama-cpp-python

For CPU only:

pip install --upgrade --quiet llama-cpp-python

For GPU with CUDA:

CMAKE_ARGS="-DGGML_CUDA=ON" FORCE_CMAKE=1 pip install --upgrade --force-reinstall llama-cpp-python --no-cache-dir

For macOS with Metal (M1/M2/M3):

CMAKE_ARGS="-DLLAMA_METAL=on" FORCE_CMAKE=1 pip install --upgrade --force-reinstall llama-cpp-python --no-cache-dir

4. 🎨 Set up React Frontend

cd Frontend-React
npm install
npm run build
cd ..

5. πŸ”‘ Configure Environment Variables

# Create .env file in Backend-API/
cp Backend-API/.env.example Backend-API/.env

# Edit Backend-API/.env with your API keys
YOUTUBE_API_KEY=your_youtube_api_key
SERPER_API_KEY=your_serper_api_key

6. πŸ“ Download Models

# Create models directory
mkdir -p Backend-API/models/llama

# Download example model (Llama 2 7B)
wget -O Backend-API/models/llama/llama-2-7b-chat.Q8_0.gguf \
  "https://huggingface.co/TheBloke/Llama-2-7B-Chat-GGUF/resolve/main/llama-2-7b-chat.Q8_0.gguf"

πŸ”§ Configuration

πŸ”‘ Required API Keys

  1. YouTube API Key:

  2. Serper API Key:

βš™οΈ System Configuration

Edit Backend-API/.env:

YOUTUBE_API_KEY=your_youtube_api_key_here
SERPER_API_KEY=your_serper_api_key_here

🎯 Usage

πŸš€ Start the Application

Option 1: Quick Start (Production Build) Not avaiable now.

# From the project root
python build_frontend.py 

Option 2: Development Mode

# Terminal 1: Start the backend server
cd Backend-API
python start_server.py

# Terminal 2: Start the React development server
cd Frontend-React
npm start

🌐 Access the Application

  • Development Mode: Open your browser and go to: http://localhost:3000 (React dev server)

πŸ’¬ Use the Chat

  1. Select a model from the dropdown menu
  2. Type your question in the chat field
  3. Press Enter or click send
  4. Watch the tools execute in real-time
  5. Receive the complete response with enriched information

πŸ› οΈ Available Tools

πŸ” Internet Search

# Example of automatic usage
"What's the weather in Madrid today?"

πŸŽ₯ Video Search

# The assistant will search for videos automatically
"Show me videos about Python programming"

πŸ’° Cryptocurrency Prices

# Query real-time prices
"What's the current price of Bitcoin and Ethereum?"

πŸ–ΌοΈ Image Generation

# Generate images with AI
"Generate an image of a space cat"

🌐 IP Information

# Get geographic information
"Where is the IP 8.8.8.8 from?"

πŸ”Ž Advanced Search

# Specialized searches
"Search for technical information about vulnerabilities"

πŸ“‚ Project Structure

IALab-Suite/
β”œβ”€β”€ πŸ“ Backend-API/
β”‚   β”œβ”€β”€ 🧠 Cortex.py              # Tool processing engine
β”‚   β”œβ”€β”€ πŸ€– Assistant.py           # Main assistant logic
β”‚   β”œβ”€β”€ πŸ” Rag.py                 # RAG system
β”‚   β”œβ”€β”€ 🌐 Api_react.py           # Flask API for React
β”‚   β”œβ”€β”€ πŸ“‘ SocketResponseHandler.py # WebSocket handling
β”‚   β”œβ”€β”€ πŸš€ start_server.py        # Main server
β”‚   β”œβ”€β”€ πŸ“ tools/                 # Modular auto-discoverable tools
β”‚   β”‚   β”œβ”€β”€ πŸ› οΈ base_tool.py       # Base tool interface
β”‚   β”‚   β”œβ”€β”€ πŸ”§ tool_registry.py   # Auto-discovery registry
β”‚   β”‚   β”œβ”€β”€ πŸ” search_tools.py    # Internet search
β”‚   β”‚   β”œβ”€β”€ πŸŽ₯ video_search_tool.py # Video search
β”‚   β”‚   β”œβ”€β”€ πŸ’° cripto_price.py     # Cryptocurrency prices
β”‚   β”‚   β”œβ”€β”€ πŸ–ΌοΈ generate_image.py   # Image generation
β”‚   β”‚   β”œβ”€β”€ 🌐 ip_info_tool.py     # IP information
β”‚   β”‚   └── πŸ”Ž advanced_search.py  # Advanced search
β”‚   β”œβ”€β”€ πŸ“ templates/             # HTML templates
β”‚   β”œβ”€β”€ πŸ“ static/                # Static files
β”‚   β”œβ”€β”€ πŸ“ models/                # LLM models
β”‚   β”œβ”€β”€ πŸ“ documents/             # Documents for RAG
β”‚   └── πŸ“ chats/                 # Conversation history
β”œβ”€β”€ πŸ“ Frontend-React/
β”‚   β”œβ”€β”€ πŸ“ src/
β”‚   β”‚   β”œβ”€β”€ πŸ“± App.js              # Main component
β”‚   β”‚   β”œβ”€β”€ πŸ“ components/         # React components
β”‚   β”‚   β”œβ”€β”€ πŸ“ context/            # State contexts
β”‚   β”‚   β”œβ”€β”€ πŸ“ hooks/              # Custom hooks
β”‚   β”‚   └── πŸ“ services/           # API services
β”‚   β”œβ”€β”€ πŸ“ public/                # Public files
β”‚   β”œβ”€β”€ πŸ“ build/                 # Production build
β”‚   └── πŸ“¦ package.json           # Node.js dependencies
β”œβ”€β”€ πŸ“„ README.md                  # This file
β”œβ”€β”€ πŸ“„ requirements.txt           # Python dependencies
└── πŸ“„ LICENSE                    # MIT License

πŸ”„ API

πŸ“‘ WebSocket Events

πŸ“€ Client Events

  • message: Send message to assistant
  • disconnect: Disconnect from server

πŸ“₯ Server Events

  • response: Assistant response (streaming)
  • console_output: Console output (tools)
  • utilities_data: Utilities data (videos, images)
  • finalization_signal: Completion signal

🌐 REST Endpoints

πŸ“Š System Information

GET /api/system-info

πŸ“ Model Management

GET /api/models
POST /api/load-model

πŸ’¬ Chat Management

GET /api/chats
POST /api/save-chat
DELETE /api/delete-chat

πŸ§ͺ Development

πŸ”§ Frontend Development

cd Frontend-React
npm start

This will start the React development server at http://localhost:3000

🐍 Backend Development

cd Backend-API
python start_server.py

This will start the Flask API server at http://localhost:8081

πŸ”„ Full Development Setup

For development, you'll need both servers running:

  1. Backend: http://localhost:8081 (Flask API)
  2. Frontend: http://localhost:3000 (React dev server)

The React development server will proxy API requests to the Flask backend automatically.

πŸ› οΈ Creating New Tools

The system now uses an automatic tool discovery and registration system. All tools inherit from BaseTool and are automatically discovered and registered.

πŸ“‹ Steps to Create a New Tool

  1. Create tool file in Backend-API/tools/my_new_tool.py
  2. Inherit from BaseTool and implement required methods
  3. The tool will be automatically discovered and registered πŸŽ‰

πŸ”§ Tool Requirements

Every tool must:

  • βœ… Inherit from BaseTool
  • βœ… Implement metadata property
  • βœ… Implement get_tool_name() class method
  • βœ… Implement execute() method

πŸ“ Tool Example

# Backend-API/tools/my_new_tool.py
from .base_tool import BaseTool, ToolMetadata, ToolCategory

class MyNewTool(BaseTool):
    
    @property
    def metadata(self) -> ToolMetadata:
        return ToolMetadata(
            name="my_new_tool",
            description="Description of what my tool does",
            category=ToolCategory.UTILITY,  # SEARCH, FINANCE, IMAGE, UTILITY, MEDIA
            requires_api_key=False,  # Set to True if API key needed
            api_key_env_var="MY_API_KEY"  # Only if requires_api_key=True
        )
    
    @classmethod
    def get_tool_name(cls) -> str:
        return "my_new_tool"
    
    def execute(self, query: str, **kwargs):
        """
        Execute the tool with the given query
        
        Args:
            query (str): Input query from the user
            **kwargs: Additional parameters
            
        Returns:
            Any: Tool result (string, dict, tuple, etc.)
        """
        # Your tool logic here
        result = f"Processing: {query}"
        
        # You can return different types:
        # - String: Simple text result
        # - Dict: Structured data
        # - Tuple: (result, additional_data) for special handling
        
        return result
    
    def is_available(self) -> bool:
        """
        Check if the tool is available (has required API keys, etc.)
        
        Returns:
            bool: True if tool can be used
        """
        # Default implementation checks API key if required
        # Override if you need custom availability logic
        return super().is_available()

🏷️ Available Categories

from .base_tool import ToolCategory

# Available categories:
ToolCategory.SEARCH      # Search and information retrieval
ToolCategory.FINANCE     # Financial data and cryptocurrency
ToolCategory.IMAGE       # Image generation and processing
ToolCategory.UTILITY     # General utilities (IP info, etc.)
ToolCategory.MEDIA       # Video, audio, media search

πŸ”§ Advanced Tool Features

For tools that need special result handling:

def execute(self, query: str, **kwargs):
    # For tools that return additional data (like video IDs)
    result_text = f"Found videos for: {query}"
    video_ids = ["abc123", "def456"]
    
    # Return tuple for special handling in Cortex
    return (result_text, video_ids)

For tools with API key validation:

def is_available(self) -> bool:
    """Custom availability check"""
    api_key = os.getenv(self.metadata.api_key_env_var)
    if not api_key:
        return False
    
    # Additional validation logic
    return self._validate_api_key(api_key)

πŸš€ Auto-Discovery

Once you create your tool file:

  1. Automatic Registration: The ToolRegistry will automatically find and register your tool
  2. Immediate Availability: Your tool becomes available to the AI assistant
  3. No Manual Configuration: No need to modify Cortex.py or other files

πŸ§ͺ Testing Your Tool

# Test your tool directly
from tools.my_new_tool import MyNewTool

tool = MyNewTool()
result = tool.execute("test query")
print(result)

πŸ“Š Tool Registry Information

The system provides runtime information about all tools:

from tools.tool_registry import ToolRegistry

registry = ToolRegistry.get_instance()

# List all registered tools
print("Available tools:", registry.list_tools())

# Get tool information
tool_info = registry.get_tool_info("my_new_tool")
print("Tool info:", tool_info)

# Execute tool through registry
result = registry.execute_tool("my_new_tool", "test query")
print("Execution result:", result.data if result.success else result.error)

🀝 Contributing

Contributions are welcome! πŸŽ‰

πŸ“‹ How to Contribute

  1. 🍴 Fork the project
  2. 🌿 Create a branch for your feature: git checkout -b feature/AmazingFeature
  3. πŸ’Ύ Commit your changes: git commit -m 'Add some AmazingFeature'
  4. πŸ“€ Push to the branch: git push origin feature/AmazingFeature
  5. πŸ”„ Open a Pull Request

πŸ› Report Bugs

Open an issue describing:

  • πŸ“ Bug description
  • πŸ”„ Steps to reproduce
  • πŸ“± Environment (OS, Python version, etc.)
  • πŸ“Έ Screenshots if relevant

πŸ’‘ Request Features

Open an issue with:

  • πŸ“ Detailed description
  • 🎯 Use cases
  • πŸ“Š Expected benefits

πŸ“Š System Information

πŸ§ͺ Tested on:

  • πŸ’» macOS: MacBook Pro M3-Pro (11 CPU cores, 14 GPU cores, 18GB RAM)
  • 🐧 Linux: AMD Ryzen 5600X, NVIDIA RTX 3060 (12GB VRAM, 32GB RAM)
  • πŸͺŸ Windows: Various configurations

🐍 Compatible Versions:

  • Python: 3.8 - 3.12
  • Node.js: 16+
  • React: 18.2+
  • Flask: 2.0+

πŸ”— Useful Links

πŸ’– Support the Project

If this project has been useful to you, consider:

  • ⭐ Giving the repository a star
  • πŸ› Reporting bugs or improvements
  • πŸ’ Contributing with code
  • β˜• Buy me a coffee: Donate

πŸ“„ License

This project is licensed under the MIT License - see the LICENSE file for more details.


πŸ€– Made with ❀️ for the AI community

⭐ If you like this project, give it a star! ⭐

Releases

No releases published

Packages

No packages published