ruslanmv/ollabridge
GitHub: ruslanmv/ollabridge
将本地和远程 GPU 资源聚合成统一 OpenAI 兼容 API 的网关工具,节点主动出连无需端口转发。
Stars: 0 | Forks: 0
Control Plane] B -->|Auto Routes| C[Local Laptop
llama3.1] B -->|Auto Routes| D[Free GPU Cloud
deepseek-r1] B -->|Auto Routes| E[Remote Workstation
mixtral] C -.->|Dials Out| B D -.->|Dials Out| B E -.->|Dials Out| B style B fill:#6366f1,stroke:#4f46e5,stroke-width:3px,color:#fff style A fill:#10b981,stroke:#059669,stroke-width:2px,color:#fff style C fill:#8b5cf6,stroke:#7c3aed,stroke-width:2px,color:#fff style D fill:#ec4899,stroke:#db2777,stroke-width:2px,color:#fff style E fill:#f59e0b,stroke:#d97706,stroke-width:2px,color:#fff ``` **核心创新:** 计算节点**主动向外连接**到您的网关。无需端口转发,无需 VPN,告别配置地狱。 ## 🚀 为什么选择 OllaBridge? ### 🎯 **单一事实来源** - ✅ **一个 URL 搞定一切** —— 您的应用无需更改代码 - ✅ **零配置** —— 无需触碰应用即可添加新 GPU - ✅ **智能路由** —— OllaBridge 自动选择最佳节点 - ✅ **OpenAI 兼容** —— 适用于任何 SDK、框架或工具 ### 🛡️ **企业级安全** - ✅ **API 密钥认证** —— 保护您的 LLM - ✅ **速率限制** —— 控制每个密钥的使用量 - ✅ **请求日志** —— 完整的审计追踪 - ✅ **加密连接** —— 远程节点使用 TLS ### 🌍 **随处运行** - ✅ **免费 GPU 云** —— Colab、Kaggle、Lightning AI(无需端口转发!) - ✅ **临时实例** —— 节点主动向外连接,IP 地址无关紧要 - ✅ **防火墙之后** —— 您的笔记本电脑可以从咖啡店 WiFi 加入 - ✅ **混合环境** —— 无缝结合本地与云端 ### 🤖 **AI Agent 就绪** - ✅ **MCP 服务器** —— Agent 可以控制您的基础设施 - ✅ **工具暴露** —— 通过工具管理节点、路由、健康状态 - ✅ **自我修复** —— 自动安装、自动配置、自动恢复 ## ⚡ 60 秒快速开始 ### 步骤 1:安装 ``` pip install ollabridge ``` ### 步骤 2:启动您的网关 ``` ollabridge start ``` **就是这样!** 您将看到: ``` ✅ Ollama installed (if needed) ✅ Model downloaded (if needed) ✅ Gateway online at http://localhost:11435 ╭─────────────────── 🚀 Gateway Ready ────────────────────╮ │ │ │ ✅ OllaBridge is Online │ │ │ │ Model: deepseek-r1 │ │ Local API: http://localhost:11435/v1 │ │ Key: sk-ollabridge-xY9kL2mN8pQ4rT6vW1zA │ │ │ │ Node join token: eyJ0eXAi... │ │ Example node command: │ │ ollabridge-node join --control http://localhost:11435 │ │ --token eyJ0eXAi... │ │ │ ╰──────────────────────────────────────────────────────────╯ ``` ### 步骤 3:开始使用! ``` from openai import OpenAI client = OpenAI( base_url="http://localhost:11435/v1", api_key="sk-ollabridge-xY9kL2mN8pQ4rT6vW1zA" ) response = client.chat.completions.create( model="deepseek-r1", messages=[{"role": "user", "content": "Hello!"}] ) print(response.choices[0].message.content) ``` **完成!** 您正在使用 OpenAI API 运行私有 LLM。 ## 🌍 60 秒添加任意 GPU 在 Colab 上有免费 GPU?还是远程工作站?立即添加: ### 在您的远程 GPU/机器上: ``` # 安装 pip install ollabridge # 加入你的网关(从网关启动时复制命令) ollabridge-node join \ --control http://YOUR_GATEWAY_IP:11435 \ --token eyJ0eXAi... ``` **就是这样!** 远程 GPU 将会: - ✅ 如有需要自动安装 Ollama - ✅ 如有需要自动下载模型 - ✅ **主动向外连接**到您的网关(无需端口转发!) - ✅ 显示为可用的计算资源 ### 您的应用自动识别 ``` # 相同的代码,现在同时使用本地 + 远程 GPU! client = OpenAI(base_url="http://localhost:11435/v1", ...) response = client.chat.completions.create(...) # Auto-routed ``` **OllaBridge 自动路由请求**至您的所有节点。 ## 🎯 真实场景 ### 场景 1:“我家里有一台游戏 PC” ``` # 在你的游戏 PC 上: ollabridge-node join --control https://your-gateway.com --token ... # 现在你的笔记本可以使用你游戏 PC 的 GPU # 即使你在咖啡店! ``` ### 场景 2:“我想使用免费的 Colab GPU” ``` # 在 Colab notebook 中: !pip install ollabridge !ollabridge-node join --control https://your-gateway.com --token ... # 现在你的生产应用可以使用免费的 Colab 算力 # Colab 会话结束?开启一个新的。零配置更改。 ``` ### 场景 3:“我有多个云 GPU” ``` # 每个 GPU 实例: ollabridge-node join --control https://gateway.company.com --token ... # 你的团队共享一个 API URL # OllaBridge 在所有 GPU 间进行负载均衡 ``` ## 💻 随处使用 ### Python (OpenAI SDK) ``` from openai import OpenAI client = OpenAI( base_url="http://localhost:11435/v1", api_key="your-key-here" ) # 聊天 response = client.chat.completions.create( model="deepseek-r1", messages=[{"role": "user", "content": "Explain quantum computing"}] ) # Embeddings embeddings = client.embeddings.create( model="nomic-embed-text", input="Hello, world!" ) ``` ### Node.js / TypeScript ``` import OpenAI from "openai"; const client = new OpenAI({ baseURL: "http://localhost:11435/v1", apiKey: process.env.OLLABRIDGE_KEY }); const completion = await client.chat.completions.create({ model: "deepseek-r1", messages: [{ role: "user", content: "Hello!" }] }); ``` ### LangChain ``` from langchain_openai import ChatOpenAI llm = ChatOpenAI( base_url="http://localhost:11435/v1", api_key="your-key-here", model="deepseek-r1" ) response = llm.invoke("What is the meaning of life?") ``` ### cURL ``` curl -X POST http://localhost:11435/v1/chat/completions \ -H "Authorization: Bearer your-key-here" \ -H "Content-Type: application/json" \ -d '{ "model": "deepseek-r1", "messages": [{"role": "user", "content": "Hello!"}] }' ``` **适用于任何 OpenAI 兼容的工具或库。** ## 🎨 尝试交互式演示客户端 想看看 OllaBridge 的实际效果?查看我们在 `example/` 文件夹中的**两键演示客户端**! ### ⚡ 快速开始 ``` # 1. 安装并启动 OllaBridge cd example ./install-ollabridge.sh # Mac/Linux # 或 .\install-ollabridge.ps1 # Windows # 2. 运行演示客户端 make run # 3. 在浏览器中打开 http://localhost:3000 ``` ### ✨ 功能特性 - 🎯 **精美 UI** —— 现代、响应式 Web 界面 - 🔌 **真实集成** —— 实际调用 OllaBridge 端点的 API - 📊 **实时指标** —— 请求统计、延迟、运行时间追踪 - 🔑 **认证演示** —— 了解 API 密钥认证如何工作 - 📝 **最佳实践** —— 生产级代码示例 ### 📚 完美学习材料 示例客户端向您展示: - ✅ 如何从浏览器连接到 OllaBridge - ✅ 如何正确处理 CORS - ✅ 如何使用 API 密钥实现认证 - ✅ 如何动态加载模型 - ✅ 如何发送聊天请求并处理响应 **[查看完整文档 →](example/README.md)** ## 🤖 AI Agent 钟爱 OllaBridge OllaBridge 内置了 **Model Context Protocol (MCP) 服务器**。 Agent 可以: - ✅ 创建注册令牌 - ✅ 列出已连接的计算节点 - ✅ 检查网关健康状态 - ✅ 通过工具管理您的 LLM 基础设施 ### 启动 MCP 服务器 ``` ollabridge-mcp ``` ### 示例:Agent 工作流 ``` # Agent 可以调用这些工具: await session.call_tool("ollabridge.enroll.create", {}) # → 返回注册 token await session.call_tool("ollabridge.runtimes.list", {}) # → 显示所有已连接的节点 await session.call_tool("ollabridge.gateway.health", {}) # → 检查网关状态 ``` **使用案例:** “嘿 Claude,把我的工作站 GPU 添加到我们的 LLM 网关中” → Agent 创建令牌,提供命令,您运行它。搞定。 ## 🔐 安全与配置 ### 认证 OllaBridge 在首次运行时自动生成一个安全的 API 密钥(保存在 `.env` 中): ``` API_KEYS=sk-ollabridge-xY9kL2mN8pQ4rT6vW1zA ``` 在您的应用中使用它: ``` # 选项 1:Bearer token headers = {"Authorization": "Bearer sk-ollabridge-..."} # 选项 2:Custom header headers = {"X-API-Key": "sk-ollabridge-..."} ``` ### 配置(`.env`) ``` # API Keys(多个用逗号分隔) API_KEYS=sk-ollabridge-abc123,sk-ollabridge-def456 # 服务器 HOST=0.0.0.0 PORT=11435 # 默认模型 DEFAULT_MODEL=deepseek-r1 DEFAULT_EMBED_MODEL=nomic-embed-text # 速率限制 RATE_LIMIT=60/minute # 安全 ENROLLMENT_SECRET=your-secret-here ENROLLMENT_TTL_SECONDS=3600 # 数据库(可选) DATABASE_URL=postgresql://user:pass@localhost/ollabridge ``` ### 注册令牌 为节点加入创建短期令牌: ``` ollabridge enroll-create --ttl 3600 ``` 出于安全考虑,令牌会自动过期。 ## 📡 API 参考 ### 核心端点 | 端点 | 方法 | 描述 | |----------|--------|-------------| | `/health` | GET | 网关健康状态 + 节点数量 | | `/v1/chat/completions` | POST | OpenAI 兼容聊天 | | `/v1/embeddings` | POST | 生成嵌入 | | `/v1/models` | GET | 列出可用模型(从节点聚合) | ### 管理端点(需要 API 密钥) | 端点 | 方法 | 描述 | |----------|--------|-------------| | `/admin/recent` | GET | 最近请求日志 | | `/admin/runtimes` | GET | 列出已连接节点 | | `/admin/enroll` | POST | 创建注册令牌 | ### 示例:检查已连接节点 ``` curl -H "X-API-Key: your-key" http://localhost:11435/admin/runtimes ``` **响应:** ``` { "runtimes": [ { "node_id": "local", "connector": "local_ollama", "healthy": true, "tags": ["local"], "models": ["deepseek-r1", "llama3.1"] }, { "node_id": "colab-gpu-1", "connector": "relay_link", "healthy": true, "tags": ["gpu", "free"], "models": ["mixtral", "codellama"] } ] } ``` ## 🏗️ 架构深度解析 ### 工作原理 1. **控制平面(Gateway)**:您的应用连接到这里 2. **节点**:任何运行模型的带有 GPU/CPU 的机器 3. **中继链接**:节点主动向外连接到网关(WebSocket) 4. **路由器**:为每个请求选择最佳节点 ### 为什么“主动向外连接”很重要 **传统方式(有问题):** ``` App → Gateway → Try to reach GPU ❌ Blocked by firewall ❌ NAT issues ❌ No public IP ``` **OllaBridge(随处可用):** ``` App → Gateway ← GPU dials in ✅ Works from anywhere ✅ No port forwarding ✅ Ephemeral IPs OK ``` ### 连接器类型 - **RelayLink**:节点通过 WebSocket 主动向外连接(默认,随处可用) - **DirectEndpoint**:通过 HTTP 连接到稳定节点(性能最佳) - **LocalOllama**:内置本地运行时(零配置) OllaBridge 自动选择合适的方式。 ## 📈 扩展性 ### 添加更多 Worker ``` ollabridge start --workers 4 ``` ### 使用 PostgreSQL ``` pip install psycopg2-binary export DATABASE_URL=postgresql://user:pass@localhost/ollabridge ollabridge start --workers 8 ``` ### 添加更多节点 ``` # 只需不断添加节点! ollabridge-node join --control ... --token ... ``` OllaBridge 自动在所有健康节点间进行负载均衡。 ## 🌍 公网访问(可选) ### 快速演示(Ngrok) ``` ollabridge start --share ``` ### 生产环境(Cloudflare Tunnel) ``` # 终端 1:启动网关 ollabridge start # 终端 2:暴露它 cloudflared tunnel --url http://localhost:11435 ``` 现在您的网关拥有一个公共 `https://` URL! **安全提示:** 对于公共网关,请务必使用 API 密钥。 ## 🎓 初学者指南 ### “我以前从未使用过 LLM” 1. 安装:`pip install ollabridge` 2. 启动:`ollabridge start` 3. 从输出中复制 API 密钥 4. 使用此代码: ``` from openai import OpenAI client = OpenAI( base_url="http://localhost:11435/v1", api_key="PASTE_KEY_HERE" ) response = client.chat.completions.create( model="deepseek-r1", messages=[{"role": "user", "content": "Explain Python in simple terms"}] ) print(response.choices[0].message.content) ``` **就是这样!** 您正在计算机上运行 AI 模型。 ### “我想添加我游戏 PC 的 GPU” 1. 在您的主计算机(网关)上: ollabridge start # 复制 "Node join token" 和网关 URL 2. 在您的游戏 PC 上: pip install ollabridge ollabridge-node join --control http://GATEWAY_IP:11435 --token TOKEN_HERE 3. 完成!您的应用现在可以使用您游戏 PC 的算力了。 ### “我想使用免费的 Colab GPU” 1. 在家启动您的网关: ollabridge start --share # 记下公共 URL (https://xxx.ngrok.io) 2. 在 Colab notebook 中: !pip install ollabridge !ollabridge-node join --control https://xxx.ngrok.io --token YOUR_TOKEN 3. 现在您的应用使用免费的 Colab GPU 了! **专业提示:** 当 Colab 断开连接时,只需重启并再次运行步骤 2。无需更改配置。 ## 🛠️ CLI 命令参考 OllaBridge 包含强大的 CLI 命令,用于诊断、测试和管理。 ### 诊断命令 #### `ollabridge doctor` 诊断您的 OllaBridge 设置(Ollama、网关、认证、CORS): ``` ollabridge doctor ``` **输出:** ``` OllaBridge Doctor ┏━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓ ┃ Check ┃ Result ┃ ┡━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┩ │ Ollama /api/tags │ ✅ OK │ │ OllaBridge /health │ ✅ OK │ │ API_KEYS configured │ ✅ yes │ │ CORS_ORIGINS │ http://localhost:5173,... │ │ Auth usage │ Use Authorization: Bearer
**为本地优先 AI 社区用 ❤️ 打造**
**停止支付云端 token 费用。使用您自己的算力。**
标签:AI开发工具, AI智能体, AI风险缓解, API代理, Beacon Object File, DeepSeek, DLL 劫持, GPU云计算, LLM, LLM评估, MCP, Mixtral, Ollama, OpenAI兼容API, Python, Unmanaged PE, 内网穿透, 分布式计算, 大语言模型, 工作站, 异常处理, 无后门, 本地模型部署, 模型网关, 模型路由, 熵值分析, 生产级环境, 私有化部署, 自动化攻击, 自愈系统, 远程访问, 逆向工具, 防御规避, 零配置