Skip to content

bai0821/opencode_platform

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

16 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

OpenCode Platform

OpenCode Platform

🚀 企業級 AI 智能平台 | Multi-Agent 協作 | RAG 知識庫 | 可擴展插件系統

功能特色快速開始系統架構API 文檔插件開發部署指南

Version Python React License


📖 簡介

OpenCode Platform 是一個功能完整的企業級 AI 智能平台,整合了:

  • 🤖 Multi-Agent 系統 - 5 個專業 Agent 協作處理複雜任務
  • 📚 RAG 知識庫 - 上傳 PDF 文件,進行語意搜尋和智能問答
  • 🔍 深度研究 - 多引擎網路搜尋,自動生成研究報告
  • 🖼️ 多模態對話 - 支援圖片上傳、文件分析
  • 💻 代碼沙箱 - 安全執行 Python/Bash 代碼,支援數據分析和圖表
  • 🧩 插件系統 - 熱插拔架構,支援自定義 Agent 和工具
  • 🔄 工作流編排 - 視覺化設計 Agent 工作流程

✨ 功能特色

🤖 Multi-Agent 協作系統

Agent 職責 能力
Dispatcher 總機 意圖識別、任務分派
Researcher 研究員 RAG 搜尋、網路研究
Writer 寫手 文案撰寫、報告生成
Coder 程式師 代碼生成、執行分析
Analyst 分析師 數據分析、圖表製作
Reviewer 審稿員 品質檢查、內容審核

📚 RAG 知識庫

  • 支援 PDF 文件上傳和解析
  • Cohere 多語言嵌入模型 (embed-multilingual-v3.0)
  • Qdrant 向量資料庫
  • 智能分塊和語意搜尋
  • 支援文件過濾和相關性評分

🔍 深度研究

  • 多引擎搜尋 (DuckDuckGo、Wikipedia、arXiv)
  • LLM 相關性檢查
  • 自動生成結構化研究報告
  • 來源引用和追蹤

🧩 插件系統

  • 熱插拔,無需重啟
  • 支援 Agent 插件和 Tool 插件
  • ZIP 上傳 / Git 安裝
  • 沙箱執行保障安全

🚀 快速開始

系統需求

  • Python: 3.11+
  • Node.js: 18+
  • Docker: 20+ (用於 Qdrant 和沙箱)
  • 記憶體: 8GB+ 建議

1️⃣ 克隆專案

git clone https://github.com/bai0821/opencode_platform.git
cd opencode_platform

2️⃣ 設置環境變數

# 複製範例文件
cp .env.example .env

# 編輯 .env,填入你的 API Keys

.env 必填項目:

# LLM API (至少填一個)
OPENAI_API_KEY=sk-proj-xxx
GEMINI_API_KEY=xxx              # 可選

# Embedding
COHERE_API_KEY=xxx

# 安全設定
JWT_SECRET=your-secret-key-change-in-production
ADMIN_PASSWORD=your-admin-password

3️⃣ 啟動 Qdrant

docker run -d \
  --name qdrant \
  -p 6333:6333 \
  -v $(pwd)/qdrant_storage:/qdrant/storage \
  qdrant/qdrant

4️⃣ 安裝後端依賴

# 建立虛擬環境(建議)
python -m venv venv

# 啟用虛擬環境
# Windows:
venv\Scripts\activate
# Linux/Mac:
source venv/bin/activate

# 安裝依賴
pip install -r requirements.txt

5️⃣ 安裝前端依賴

cd frontend
npm install
cd ..

6️⃣ 啟動服務

方式 A:使用啟動腳本(推薦)

# Windows
powershell -ExecutionPolicy Bypass -File start.ps1

# Linux/Mac
bash deploy.sh

方式 B:手動啟動

# 終端 1:後端
python run.py api

# 終端 2:前端
cd frontend
npm run dev

7️⃣ 訪問服務

8️⃣ 預設帳號

帳號 密碼 角色
admin admin123 (或 .env 中設定的) 管理員

🏗️ 系統架構

┌─────────────────────────────────────────────────────────────────┐
│                         Frontend                                 │
│                    React + Tailwind CSS                         │
└─────────────────────────────────────────────────────────────────┘
                              │
                              ▼
┌─────────────────────────────────────────────────────────────────┐
│                        API Gateway                               │
│                    FastAPI + JWT Auth                           │
├─────────────────────────────────────────────────────────────────┤
│   /chat   │  /research  │  /sandbox  │  /plugins  │  /workflow │
└─────────────────────────────────────────────────────────────────┘
                              │
                              ▼
┌─────────────────────────────────────────────────────────────────┐
│                    Agent Coordinator                             │
│  ┌──────────┐ ┌──────────┐ ┌──────────┐ ┌──────────┐           │
│  │Dispatcher│ │Researcher│ │  Coder   │ │ Analyst  │           │
│  └──────────┘ └──────────┘ └──────────┘ └──────────┘           │
│                                                                  │
│  ┌────────────────────────────────────────────────────────────┐ │
│  │                    Plugin Agents                            │ │
│  │    (Stock Analyst, Weather Tool, Custom Agents...)         │ │
│  └────────────────────────────────────────────────────────────┘ │
└─────────────────────────────────────────────────────────────────┘
                              │
                              ▼
┌─────────────────────────────────────────────────────────────────┐
│                       Services Layer                             │
│  ┌──────────┐ ┌──────────┐ ┌──────────┐ ┌──────────┐           │
│  │   RAG    │ │ Sandbox  │ │  Search  │ │ Workflow │           │
│  │ Service  │ │ Service  │ │ Service  │ │  Engine  │           │
│  └──────────┘ └──────────┘ └──────────┘ └──────────┘           │
└─────────────────────────────────────────────────────────────────┘
                              │
                              ▼
┌─────────────────────────────────────────────────────────────────┐
│                      Infrastructure                              │
│  ┌──────────┐ ┌──────────┐ ┌──────────┐ ┌──────────┐           │
│  │  Qdrant  │ │  OpenAI  │ │  Cohere  │ │  Docker  │           │
│  │ (Vector) │ │  (LLM)   │ │(Embedding)│ │(Sandbox) │           │
│  └──────────┘ └──────────┘ └──────────┘ └──────────┘           │
└─────────────────────────────────────────────────────────────────┘

📁 專案結構

opencode_platform/
├── src/opencode/              # 後端源碼
│   ├── api/                   # FastAPI 路由
│   ├── agents/                # Multi-Agent 系統
│   │   ├── base.py           # Agent 基類
│   │   ├── coordinator.py    # 協調器
│   │   ├── dispatcher.py     # 總機 Agent
│   │   └── specialists.py    # 專業 Agents
│   ├── services/             # 服務層
│   │   └── knowledge_base/   # RAG 服務
│   ├── plugins/              # 插件系統
│   ├── workflow/             # 工作流引擎
│   ├── sandbox/              # 代碼沙箱
│   ├── auth/                 # 認證授權
│   └── control_plane/        # 審計、成本追蹤
│
├── frontend/                  # 前端源碼
│   ├── src/
│   │   ├── components/       # React 組件
│   │   └── App.jsx          # 主應用
│   ├── package.json
│   └── vite.config.js
│
├── plugins/                   # 插件目錄
│   ├── stock-analyst/        # 範例:股票分析 Agent
│   ├── weather-tool/         # 範例:天氣工具
│   └── PLUGIN_DEV_GUIDE.md   # 插件開發指南
│
├── docker/                    # Docker 配置
├── nginx/                     # Nginx 配置
├── tests/                     # 測試文件
├── docs/                      # 文檔
│
├── .env.example              # 環境變數範例
├── requirements.txt          # Python 依賴
├── docker-compose.yml        # Docker Compose
├── run.py                    # 啟動腳本
└── README.md                 # 本文件

📡 API 文檔

主要端點

端點 方法 說明
/api/chat/stream POST 串流對話 (SSE)
/api/research/deep POST 深度研究
/api/upload POST 上傳文件
/api/documents GET 文件列表
/api/sandbox/execute POST 執行代碼
/api/plugins GET 插件列表
/api/workflows GET/POST 工作流管理
/api/agents GET Agent 列表

完整 API 文檔

啟動服務後訪問:http://localhost:8000/docs


🧩 插件開發

快速開始

  1. plugins/ 目錄創建插件文件夾
  2. 添加 plugin.jsonmain.py
  3. 在管理介面啟用插件

Agent 插件範例

# plugins/my-agent/main.py
from opencode.plugins.manager import AgentPlugin

class PluginImpl(AgentPlugin):
    @property
    def agent_name(self) -> str:
        return "my_agent"
    
    @property
    def agent_description(self) -> str:
        return "我的自定義 Agent"
    
    async def process_task(self, task_description, parameters, context):
        # 你的邏輯
        return {"success": True, "output": "Hello from plugin!"}

plugin.json

{
  "id": "my-agent",
  "name": "我的 Agent",
  "version": "1.0.0",
  "type": "agent",
  "entry_point": "main"
}

詳見 插件開發指南


🐳 Docker 部署

開發環境

docker-compose up -d

生產環境(含 Nginx)

docker-compose --profile production up -d

服務管理

# 查看日誌
docker-compose logs -f

# 停止服務
docker-compose down

# 重啟單個服務
docker-compose restart api

⚙️ 配置說明

環境變數

變數 必填 說明 預設值
OPENAI_API_KEY OpenAI API Key -
COHERE_API_KEY Cohere API Key -
GEMINI_API_KEY Google Gemini API Key -
JWT_SECRET JWT 密鑰 -
ADMIN_PASSWORD 管理員密碼 admin123
QDRANT_HOST Qdrant 主機 localhost
QDRANT_PORT Qdrant 端口 6333
LOG_LEVEL 日誌等級 INFO

Qdrant 配置

預設使用 Collection:opencode_documents

向量維度:1024 (Cohere embed-multilingual-v3.0)


🧪 測試

# 運行所有測試
pytest

# 運行特定測試
pytest tests/test_rag.py

# 測試覆蓋率
pytest --cov=src/opencode

⚠️ 常見問題

Q: Qdrant 連接失敗?

確保 Docker 容器正在運行:

docker ps | grep qdrant

Q: 前端無法連接後端?

檢查 CORS 設定和後端是否在 8000 端口運行。

Q: 沙箱執行失敗?

確保 Docker 服務正在運行,且有足夠權限。

Q: API Key 錯誤?

確認 .env 文件中的 Key 格式正確,沒有多餘空格。


🤝 貢獻

歡迎貢獻!請查看 CONTRIBUTING.md 了解詳情。

開發流程

  1. Fork 本專案
  2. 創建功能分支 (git checkout -b feature/amazing-feature)
  3. 提交更改 (git commit -m 'Add amazing feature')
  4. 推送分支 (git push origin feature/amazing-feature)
  5. 開啟 Pull Request

📄 授權

本專案採用 MIT 授權 - 詳見 LICENSE 文件


🙏 致謝


Built with ❤️ by OpenCode Team

About

No description, website, or topics provided.

Resources

License

Contributing

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors