跳到正文
原文
Hacker News· xamrayev·· 3 小时前精选AI 评分68

Nexus-CLI 开源纯 Go 桥接工具,支持 DeepSeek R1/V3、Claude Code 和 Ollama

Nexus-CLI – Pure Go Bridge to DeepSeek R1/V3 with Claude Code and Ollama Support

AI 导读

Nexus-CLI 以纯 Go 构建 DeepSeek V3 与 R1 网页桥接,可供应用和编码智能体通过免费账号使用,无需官方付费 API key。它提供交互式终端、本地代理及 OpenAI、Anthropic Messages、OpenAI Responses 和 Ollama API 兼容层,可接入 Claude Code、Codex、Cursor 等工具。

推荐理由

原文集中列出兼容接口、性能数据、构建命令和多工具接入路径,可用于评估接入 DeepSeek 所需的改动。

正文 · AI 翻译

Nexus-CLI(面向 Golang 的 DeepSeek Web 桥接器) ⚡

英语 | 俄语 | 乌兹别克语


一款高性能 Golang CLI 工具和本地 API 代理服务器,可让任何应用程序或编程智能体通过免费网页账户(chat.deepseek.com)连接 DeepSeek V3(deepseek-chat)和 R1(deepseek-reasoner / 思考)模型,而无需官方付费 DeepSeek API 密钥。

基于对 Node.js(FreeDeepseekAPI-EN)和 Python(deepseek_bridge)项目的深入分析,使用纯 Go(Golang)从头重写,具有零运行时依赖。


🚀 主要功能

  1. Pure Go Parallel PoW (Proof-of-Work) Solver:
    • 使用 DeepSeekHashV1 算法解决 DeepSeek 服务器挑战(Keccak-f[1600] 1..23 轮 SHA3-256),并跨 CPU 核心并行执行。
    • 仅用 约 40–50 毫秒即可解决难度为 144,000 的挑战(无需 CGO、WASM 或 Python 依赖)。
  2. Interactive Terminal Chat (REPL):
    • 以专用样式(斜体/青色)实时流式呈现 R1 模型的思考过程(reasoning_content)。
    • 精致的 ANSI 界面,配有彩色提示符和动态加载转圈指示器。
    • 内置斜杠命令:/help、/new、/model、/thinking、/search、/whoami、/clear、/exit。
  3. One-Off & Unix Pipe Support:
    • 直接 CLI 查询:nexus "What is quantum computing?"
    • Linux/macOS 管道工作流:cat main.go | nexus "Review this code for security and performance"
  4. 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 100% 兼容!)
    • POST /v1/responses(OpenAI Responses API)
    • GET /v1/models 和 GET /v1/model-capabilities
    • GET /v1/sessions 和 POST /v1/sessions/reset
    • 可无缝连接 Open WebUI、Continue.dev、Cursor、Cline 以及任何其他 OpenAI/Anthropic 客户端。
  5. Native Ollama API Emulation 🦙:
    • 模拟 GET /api/tags、POST /api/chat、POST /api/generate、GET /api/version。
    • 直接即插即用地兼容 Open WebUI、Dify、AnythingLLM、Cursor、LlamaIndex 和官方 Ollama SDK。
  6. Structured Outputs & JSON Schema 🎯:
    • 在 CLI、Ollama 和 OpenAI 端点上强制使用严格的 JSON 输出或根据 JSON Schema 进行验证。
  7. Universal Integrations (Launcher) 🚀:
    • 为 Claude Code、DeepSeek Harness、Codex、OpenCode、Goose 和 Aider 提供一键启动器(Nexus 自动在后台启动代理)。
  8. Multi-Account Pool 👥:
    • 使用轮询调度轮换多个 DeepSeek 账户,以避开限流障碍(HTTP 429)。
  9. Authentication Management (nexus auth):
    • 手动登录:nexus auth login(从浏览器 LocalStorage 中提取 userToken)
    • 通过 Chrome 自动完成:nexus auth chrome(通过 CDP 从浏览器内存中读取会话令牌)
    • 账户检查:nexus auth whoami
  10. 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 账户有 3 种方式:

1. 交互式 CLI 提示:

./bin/nexus auth login

你将收到提示,要求输入 userToken:

  1. 在浏览器中打开 https://chat.deepseek.com。
  2. 按 F12(macOS 上则按 Cmd+Option+I)。
  3. 进入 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 输出或符合指定模式:

# 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 许可证发布。

来源:Hacker News · github.com