Skip to main content

Decentralized P2P network for AI model hosting and inference

Project description

🐝 Bee2Bee: The Neural Consensus P2P Network

PyPI version License: MIT FastAPI

Bee2Bee is a decentralized, peer-to-peer neural consensus engine designed to make AI inference accessible, transparent, and resilient. It allows anyone to contribute compute to a global mesh and anyone to consume it through a unified, high-performance API.


🏗️ Architecture

Bee2Bee operates as a Decentralized Mesh where every node is both a consumer and potentially a provider:

  • Neural Nodes: Host models (Ollama, HF, Transformers) and register via the Global Registry.
  • Consensus Router: Intelligently routes requests to the lowest-latency, highest-reliability nodes.
  • API Sidecar: Every node optionally hosts a FastAPI management layer for real-time telemetry.

🚀 Quick Start (Production)

1. Installation

pip install bee2bee

2. Launch a Worker Node (The Consumer/Provider)

Run a node that automatically joins the network and hosts a model:

# Deploys a Llama3 provider via Ollama with an API sidecar on port 8000
python -m bee2bee serve-ollama --model llama3 --api-port 8000

3. Connect to the Mesh

To join the global discovery map on the Chatit.cloud Dashboard:

python -m bee2bee config bootstrap_url ws://bootstrap.chatit.cloud:4003

🛠️ Developer Guide

Developing Solutions (Python)

Integrate P2P intelligence directly into your apps using our rich-ready SDK:

import asyncio
from bee2bee import P2PNode

async def main():
    # Initialize P2P entrypoint
    node = P2PNode()
    await node.start()
    
    # Discovery
    providers = await node.discover_providers(model="llama3")
    
    # Intelligent Request
    response = await node.request_generation(
        provider_id=providers[0].id,
        prompt="Synthesize a response for decentralized governance."
    )
    print(f"P2P Intelligence: {response['text']}")

asyncio.run(main())

Interactive Learning

Check out our Jupyter Guide for a step-by-step walkthrough of the p2p architecture.


🌐 FastAPI Integration

Bee2Bee nodes now support a native FastAPI sidecar. This allows you to monitor your node health and peer list via standard HTTP requests:

  • Health Check: GET http://localhost:8000/
  • Peers List: GET http://localhost:8000/peers
  • Cloud Inference: POST http://localhost:8000/chat

🤝 Community & Support

Built with ❤️ by the ConnectIT Team for a decentralized future.

🚀 Quick Start Guide

1. Main End Point (The Supervisor)

This runs the core API server. Every network needs at least one Main Point.

Run Locally:

# Starts the API on Port 4002 and P2P Server on Port 4003
python -m bee2bee api

Output:

  • API: http://127.0.0.1:4002 (Docs: /docs)
  • P2P: ws://127.0.0.1:4003

2. Desktop App (The Dashboard)

A modern UI to visualize the network and chat with models.

Prerequisites: Node.js 20+

Run Locally:

cd electron-app
npm install      # First time only
npm run dev

Usage:

  • Open the App.
  • It connects to http://localhost:4002 by default.
  • Go to "Chat" to talk to available providers.
  • See MANUAL_TESTING.md for detailed testing steps.

3. Worker Node (The AI Provider)

Run this on any machine (or the same machine) to share an AI model.

Step A: Configure (Tell the node where the Main Point is)

# If running on the SAME machine as Main Point:
python -m bee2bee config bootstrap_url ws://127.0.0.1:4003

# If running on a DIFFERENT machine (LAN/WAN):
python -m bee2bee config bootstrap_url ws://<MAIN_POINT_IP>:4003

Step B: Deploy Model

Option 1: Hugging Face (Default) Uses transformers to run models like GPT-2, Llama, etc. on CPU/GPU.

# Deploys distilgpt2 (CPU friendly)
python -m bee2bee deploy-hf --model distilgpt2

Option 2: Ollama (Universal) Uses your local Ollama instance to serve models like Llama3, Mistral, Gemma, etc. Prerequisite: Install and run Ollama

# Serve a model (e.g., llama3)
python -m bee2bee serve-ollama --model llama3

Note: This creates a separate peer node on your machine.

Option 3: Remote Inference (Cloud) Execute models entirely on Hugging Face's servers via Inference API. No GPU required on your local machine!

# Deploys Zephyr 7B (Runs on Hugging Face Cloud)
python -m bee2bee deploy-hf --model HuggingFaceH4/zephyr-7b-beta --remote --token YOUR_HF_TOKEN

Note: The node acts as a proxy/gateway to the remote model.


4. Bee2Bee Cloud (Google Colab)

Run a powerful node on Google's free GPU infrastructure using our Hybrid Tunneling setup.

Notebook Location: notebook/ConnectIT_Cloud_Node.ipynb

How it Works (Hybrid Tunneling): To bypass Colab's network restrictions, we use two tunnels:

  1. API Tunnel (Cloudflare): Provides a stable HTTPS URL (trycloudflare.com) for the Desktop App to connect to.
  2. P2P Tunnel (Bore): Provides a raw WebSocket URL (bore.pub) for other Worker Nodes to connect to.

Instructions:

  1. Open the Notebook in Google Colab.
  2. Run "Install Dependencies".
  3. Run "Configure Hybrid Tunnels" (Installs cloudflared & bore).
    • Wait for it to output the URLs.
  4. Run "Run Bee2Bee Node".
    • It automatically configures itself to announce the Bore address.

Connecting your Desktop App to Colab:

  1. Copy the Cloudflare URL (e.g., https://funny-remote-check.trycloudflare.com).
  2. Open Desktop App -> Settings.
  3. Paste into "Main Point URL".

🛠 Advanced Configuration

Environment Variables

You can override settings using ENV vars:

Variable Description Default
BEE2BEE_PORT Port for P2P Server 4003 (Worker) / 4003 (API)
BEE2BEE_HOST Bind Interface 0.0.0.0
BEE2BEE_ANNOUNCE_HOST Public Hostname (for NAT/Tunnel) Auto-detected
BEE2BEE_ANNOUNCE_PORT Public Port (for NAT/Tunnel) Auto-detected
BEE2BEE_BOOTSTRAP URL of Main Point None

Troubleshooting

  • "Connection Refused": Ensure the bootstrap_url is correct and reachable (try ping).
  • "0 Nodes Connected": Check if the Worker Node can reach the Main Point's P2P address (WSS).
  • Colab Disconnects: Ensure the Colab tab stays open. Tunnels change if you restart the notebook.

🤝 Contributing

Contributions are welcome! Please open an issue or PR on GitHub.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

bee2bee-3.3.8.tar.gz (45.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

bee2bee-3.3.8-py3-none-any.whl (41.9 kB view details)

Uploaded Python 3

File details

Details for the file bee2bee-3.3.8.tar.gz.

File metadata

  • Download URL: bee2bee-3.3.8.tar.gz
  • Upload date:
  • Size: 45.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.7

File hashes

Hashes for bee2bee-3.3.8.tar.gz
Algorithm Hash digest
SHA256 9b309bc8252ecdafc5aa19436139199e65d7bc74693842121ae8b8ed0d48f6e0
MD5 91ec8e17e088ae5a1ab8efffdd992505
BLAKE2b-256 272576ad246b765fa241fdabb1684c9d5f9e4139738c79a417d0ffb94c68b694

See more details on using hashes here.

File details

Details for the file bee2bee-3.3.8-py3-none-any.whl.

File metadata

  • Download URL: bee2bee-3.3.8-py3-none-any.whl
  • Upload date:
  • Size: 41.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.7

File hashes

Hashes for bee2bee-3.3.8-py3-none-any.whl
Algorithm Hash digest
SHA256 c5734ebff6e24c8be12ec8594f827c80d2563e5e60f77279d1dbace9ffd0e5be
MD5 4714fc45f4a1a2f871202c10d3f83eaf
BLAKE2b-256 9e937d6c603de2b6a0cfb888480776d0f29e4ac13056adf527fe65626b7f75c5

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page