Nexus-CLI 純 Go 橋接 DeepSeek R1/V3 相容 Claude Code 與 Ollama
Nexus-CLI – Pure Go Bridge to DeepSeek R1/V3 with Claude Code and Ollama Support
Nexus-CLI 是一款純 Go 實現的 CLI 工具,能在本地以 OpenAI API 風格連線 DeepSeek R1/V3,並相容 Claude Code 與 Ollama。
Nexus-CLI 讓開發者可在本地以 OpenAI API 風格連線 DeepSeek R1/V3 省去 API 金鑰 提升開發效率
Nexus-CLI (DeepSeek 網路橋接 for Golang) ⚡
一個高效能的 Golang CLI 工具與本機 API 代理伺服器,允許任何應用程式或程式碼代理連線至 DeepSeek V3 (deepseek-chat) 與 R1 (deepseek-reasoner / 思考) 模型,透過免費網路帳號 (chat.deepseek.com) 連線,無需官方付費 DeepSeek API 金鑰。
完全以純 Go (Golang) 重新編寫,基於對 Node.js (FreeDeepseekAPI-EN) 與 Python (deepseek_bridge) 專案的深入分析,並擁有 零執行期相依性。
🚀 主要功能
- Pure Go Parallel PoW (Proof-of-Work) Solver:
- 使用
DeepSeekHashV1演算法(Keccak-f[1600] 1..23 回合 SHA3-256)並行於 CPU 核心,解決 DeepSeek 伺服器挑戰。 - 以僅 ~40–50 毫秒 的時間解決難度 144,000 的挑戰(不需要 CGO、WASM 或 Python 相依性)。
- 使用
- Interactive Terminal Chat (REPL):
- 以專屬樣式(斜體/青色)即時串流 R1 模型的思考過程 (
reasoning_content)。 - 精緻的 ANSI UI,配色提示與動畫載入旋轉圖示。
- 內建斜線指令:
/help、/new、/model、/thinking、/search、/whoami、/clear、/exit。
- 以專屬樣式(斜體/青色)即時串流 R1 模型的思考過程 (
- One-Off & Unix Pipe Support:
- 直接 CLI 查詢:
nexus "What is quantum computing?" - Linux/macOS 管道工作流程:
cat main.go | nexus "Review this code for security and performance"
- 直接 CLI 查詢:
- OpenAI, Anthropic & Ollama Compatible Proxy Server (
nexus serve):POST /v1/chat/completions(OpenAI 格式,SSE 串流,與 JSON)POST /v1/messages(Anthropic Messages API — 完全相容於 Claude Code 與 Anthropic SDK!)POST /v1/responses(OpenAI 回應 API)GET /v1/models與GET /v1/model-capabilitiesGET /v1/sessions與POST /v1/sessions/reset- 與 Open WebUI、Continue.dev、Cursor、Cline 以及任何其他 OpenAI/Anthropic 客戶端無縫連線。
- Native Ollama API Emulation 🦙:
- 模擬
GET /api/tags、POST /api/chat、POST /api/generate、GET /api/version。 - 直接即插即用相容於 Open WebUI、Dify、AnythingLLM、Cursor、LlamaIndex 與官方 Ollama SDK。
- 模擬
- Structured Outputs & JSON Schema 🎯:
- 強制嚴格 JSON 輸出或對 CLI、Ollama 與 OpenAI 端點進行 JSON Schema 驗證。
- Universal Integrations (Launcher) 🚀:
- 一鍵啟動器,支援 Claude Code、DeepSeek Harness、Codex、OpenCode、Goose 與 Aider(Nexus 會自動在背景啟動代理)。
- Multi-Account Pool 👥:
- 使用迴圈輪替排程,旋轉多個 DeepSeek 帳號,以消除速率限制障礙(HTTP 429)。
- Authentication Management (
nexus auth):- 手動登入:
nexus auth login(從瀏覽器 LocalStorage 擷取userToken) - Chrome 自動化:
nexus auth chrome(透過 CDP 從瀏覽器記憶體讀取會話令牌) - 帳號檢查:
nexus auth whoami
- 手動登入:
- System Diagnostics (Doctor):
nexus doctor— 即時檢查令牌有效性、伺服器連線、PoW 解題效能與會話建立。
📦 安裝與建置
需 Go 1.20+:
# Clone repository and navigate to directory: git clone https://github.com/xamrayev/nexus-cli.git cd nexus-cli # Build the executable binary: go build -o bin/nexus . # Install globally to system PATH (optional): go install .
🔑 認證(帳號連結)
連結 DeepSeek 帳號有三種方式:
1. 互動式 CLI 提示:
./bin/nexus auth login
將會提示您輸入您的 userToken:
- 在瀏覽器開啟
https://chat.deepseek.com。 - 按
F12(或 macOS 上的Cmd+Option+I)。 - 導航至
Application→Local Storage→https://chat.deepseek.com→ 複製userToken值並貼入提示。
2. Chrome 自動化(CDP):
./bin/nexus auth chrome
此功能會自動啟動 Chrome 視窗。登入後,Nexus 會安全擷取並儲存會話令牌。
3. 透過 .env 檔案:
在專案根目錄建立一個 .env 檔案:
DEEPSEEK_TOKEN=your_deepseek_token_here
💡 使用範例
1. 互動式聊天(REPL)
./bin/nexus chat
或直接:
./bin/nexus
即時 R1 推理串流:
nexus ❯ Why is the sky blue?
💭 Thinking Process:
The user is asking about the physical cause behind the color of the sky...
Need to explain the mechanism of Rayleigh scattering of sunlight by atmospheric molecules...
🤖 DeepSeek (deepseek-reasoner):
The primary reason the sky appears blue is due to a phenomenon called Rayleigh scattering...
2. 一次性提示
./bin/nexus "Provide 3 key facts about general relativity"3. 透過 Unix 管道進行程式碼分析
cat main.go | ./bin/nexus "Analyze this code for security vulnerabilities and performance bottlenecks"
4. 執行本機 API 代理伺服器
./bin/nexus serve --port 9655
您現在可以將任何工具(Cursor、Open WebUI、Claude Code)路由至 http://localhost:9655/v1!
OpenAI 格式範例 cURL 請求:
curl http://localhost:9655/v1/chat/completions \ -H "Content-Type: application/json" \ -d '{ "model": "deepseek-reasoner", "messages": [{"role": "user", "content": "Hello!"}], "stream": true }'
5. 原生 Ollama API 模擬 🦙
Nexus 實作 Ollama API 規範。Open WebUI、Dify、AnythingLLM、Cursor、LlamaIndex 與官方 Ollama 函式庫皆可直接連線至 http://localhost:9655:
# 1. Fetch available models (Ollama format) curl http://localhost:9655/api/tags # 2. Ollama Chat request (NDJSON streaming) curl http://localhost:9655/api/chat -d '{ "model": "deepseek-reasoner", "messages": [{"role": "user", "content": "Hello!"}], "stream": true }'
使用官方 Python Ollama SDK:
import ollama client = ollama.Client(host="http://localhost:9655") resp = client.chat(model="deepseek-reasoner", messages=[ {"role": "user", "content": "Write a simple HTTP server in Go"} ]) print(resp["message"]["content"])
6. 結構化輸出 & JSON Schema 🎯
強制嚴格 JSON 輸出或符合指定的 Schema:
# 1. Direct JSON from CLI (pipeable to jq) ./bin/nexus "Top 3 programming languages and their primary domains" --format json | jq . # 2. Via Ollama API: curl http://localhost:9655/api/chat -d '{ "model": "deepseek-reasoner", "messages": [{"role": "user", "content": "List 3 fruits in JSON"}], "format": "json", "stream": false }' # 3. Via OpenAI API (response_format): curl http://localhost:9655/v1/chat/completions -d '{ "model": "deepseek-reasoner", "messages": [{"role": "user", "content": "Return device specs as JSON"}], "response_format": {"type": "json_object"} }'
7. 通用整合(啟動器) 🚀
使用單一指令啟動編碼工具與代理 — Nexus 會在背景自動啟動代理伺服器:
# 1. Claude Code CLI (powered by DeepSeek R1 / V3) ./bin/nexus launch claude ./bin/nexus launch claude -p "Refactor this Go code" # 2. Official DeepSeek Harness CLI (@deepseek-ai/dsh) ./bin/nexus launch dsh # 3. OpenAI Codex CLI (auto-configured with responses wire API) ./bin/nexus launch codex # 4. OpenCode CLI (with automated config injection) ./bin/nexus launch opencode # 5. Block Goose AI Agent (via OpenAI provider) ./bin/nexus launch goose # 6. Aider Pair Programming CLI (with DeepSeek R1) ./bin/nexus launch aider # 7. ChatGPT Desktop (macOS) & local bridge ./bin/nexus launch chatgpt # 8. Multi-Account Pool Monitor ./bin/nexus launch pool # 9. DeepSeek Agentic Eval & Benchmark Harness ./bin/nexus launch harness
8. 多帳號池 👥
透過輪詢多個 DeepSeek 帳號使用迴圈輪替,避免速率限制(HTTP 429):
# Add a new account ./bin/nexus auth add acc2 --chrome # List accounts and check their status ./bin/nexus auth list # Switch active account ./bin/nexus auth switch acc2 # Validate all accounts in the pool ./bin/nexus auth test
9. 系統診斷(Doctor)
./bin/nexus doctor
📁 專案結構
nexus-cli/
├── bin/
│ └── nexus # Compiled binary executable
├── cmd/
│ └── nexus/main.go # CLI command dispatcher
├── pkg/
│ ├── deepseek/
│ │ ├── pow.go # Pure Go parallel DeepSeekHashV1 Keccak PoW solver
│ │ ├── pow_test.go # PoW test suite & benchmarks
│ │ ├── stream.go # SSE JSON patch & OpenAI stream parser
│ │ ├── stream_test.go # Stream tests
│ │ ├── auth.go # Token, session, and profile manager
│ │ ├── chrome_auth.go # Automated Chrome CDP authentication
│ │ ├── client.go # DeepSeek Web API client (Chat, Sessions, Auto-retry)
│ │ └── types.go # Model configs and type definitions
│ ├── server/
│ │ ├── server.go # Local HTTP proxy server (Routing, CORS, Auth)
│ │ ├── server_test.go # Server endpoint unit tests
│ │ ├── openai.go # OpenAI Chat Completions API adapter
│ │ ├── anthropic.go # Anthropic Messages API adapter (for Claude Code)
│ │ └── session.go # Agent session isolation and cleanup
│ ├── launcher/
│ │ └── launcher.go # Launchers for Claude Code, Codex, Goose, Aider, etc.
│ └── cli/
│ ├── terminal.go # ANSI styling, banners, and spinners
│ ├── repl.go # Interactive terminal chat & slash commands
│ ├── runner.go # Single-prompt and Unix pipe runner
│ └── doctor.go # End-to-end system diagnostics
├── main.go # Application entry point
├── go.mod # Go module definition
├── README.md # Main documentation (English)
├── README.ru.md # Russian documentation (Русский)
└── README.uz.md # Uzbek documentation (O'zbekcha)
📄 授權
採用 MIT 授權協議。