logo
0
0
WeChat Login

OpenCode AI + Baidu Qianfan (Coding Plan)

This project demonstrates OpenCode AI configured with Baidu Qianfan Coding Plan as the LLM provider.

OpenCode Version

Source Code

OpenCode 源码位于 opencode-source/ 目录,用于自定义构建。

# 从源码构建
cd opencode-source
bun install
bun run build

详见 opencode-source/SOURCE.md

Modifications for Baidu Qianfan

本项目通过配置文件实现百度千帆集成,未修改 OpenCode 源码。如需深度定制,可在 opencode-source/ 中修改。

配置修改说明

文件修改内容
.opencode/opencode.json设置 provider.anthropic.options.baseURL 指向百度千帆
.opencode/oh-my-opencode.json配置 Agent 模型映射,使用千帆支持的模型名称
.env.local存储 QIANFAN_API_KEY

关键配置

// .opencode/opencode.json
{
  "provider": {
    "anthropic": {
      "options": {
        "baseURL": "https://qianfan.baidubce.com/anthropic/coding/v1"
      }
    }
  }
}

Baidu Qianfan Coding Plan - Supported Models

百度千帆 Coding Plan 支持以下模型:

Model IDDescriptionBest For
qianfan-code-latest千帆编程专用模型编码、Debug、代码生成
kimi-k2.5Kimi K2.5 (262K context)代码探索、长文档分析
deepseek-v3.2DeepSeek V3.2复杂推理、架构决策
glm-5GLM-5中文创意、写作
minimax-m2.5MiniMax M2.5前端/UI、多模态任务

Model Name Format

在配置中使用 anthropic/<model-id> 格式:

{
  "agents": {
    "oracle": {
      "model": "anthropic/deepseek-v3.2"
    },
    "explore": {
      "model": "anthropic/kimi-k2.5"
    }
  }
}

百度千帆网关会将请求路由到对应的模型。

Quick Start

Prerequisites

  1. OpenCode AI CLI installed (v1.2.26+)
  2. Baidu Qianfan Coding Plan API key
  3. Node.js 18+

Setup

# Clone repository
git clone <repo-url>
cd opencode-omo-baidu-qianfan

# Install dependencies
cd .opencode && npm install && cd ..

# Configure API key
cp .env.local.example .env.local
# Edit .env.local with your QIANFAN_API_KEY

Environment Variables

# .env.local
QIANFAN_API_KEY=bce-v3/ALTAKSP-...

# Optional: AK/SK authentication
# QIANFAN_ACCESS_KEY=
# QIANFAN_SECRET_KEY=

Quick Start with qf-env

~/.zshrc~/.bashrc 中添加以下 alias,使用千帆模型启动 OpenCode(带 oh-my-opencode 配置):

# 使用百度千帆模型启动 OpenCode
alias qf-env='source ~/.local/bin/opencode-qf 2>&1 || echo "---" && echo "OPENCODE_CONFIG_DIR=$OPENCODE_CONFIG_DIR"'

添加后运行 source ~/.zshrc 生效。

作用qf-env 会设置 OPENCODE_CONFIG_DIR 环境变量,指向本项目的 .opencode 配置目录,使 OpenCode 使用百度千帆模型和 oh-my-opencode 的 Agent 模型映射。

Project Structure

.
├── .claude/                       # Claude Code 配置 (符号链接为 .opencode)
│   ├── opencode.json              # Provider config (Baidu Qianfan)
│   └── oh-my-opencode.json        # Agent model mappings
├── .opencode -> .claude           # 符号链接
│   └── skills/                    # Skills 符号链接 (可选)
│       ├── feishu-progress-reporter -> ~/.config/opencode/skills/...
│       ├── multi-agent-orchestrator -> ~/.config/opencode/skills/...
│       └── worktree-branch -> ~/.config/opencode/skills/...
├── opencode-source/               # OpenCode 源码 (v1.2.26)
│   ├── packages/opencode/         # 核心 CLI 代码
│   ├── SOURCE.md                  # 源码说明
│   └── ...
├── .env.local                     # API credentials (gitignored)
├── .env.local.example             # API credentials template
├── opencode-qf                    # 本地启动脚本
├── install.sh                     # 安装脚本
├── AGENTS.md                      # Agent model assignments
├── CLAUDE.md                      # Claude Code project guide
└── README.md                      # This file

Agent Model Assignments

AgentModelUse Case
sisyphusqianfan-code-latestMain worker, coding
oracledeepseek-v3.2Architecture consulting
explorekimi-k2.5Code exploration (262K context)
visual-engineeringminimax-m2.5Frontend/UI tasks
artistry/writingglm-5Creative/writing tasks

See AGENTS.md for complete model assignments.

How It Works

  1. Request Flow: OpenCode → Baidu Qianfan Gateway → Backend Model
  2. Model Routing: Gateway maps anthropic/* requests to Qianfan models
  3. Authentication: API key passed via Authorization header
┌─────────────┐     ┌─────────────────────────┐     ┌──────────────┐
│  OpenCode   │────▶│  Baidu Qianfan Gateway  │────▶│  Model APIs  │
│  (anthropic)│     │  (anthropic/coding)     │     │  (千帆模型)  │
└─────────────┘     └─────────────────────────┘     └──────────────┘

Limitations

  • Only Coding Plan supported models are available
  • Model names must match Qianfan's expected format
  • No fallback to other providers

Resources

License

MIT

About

No description, topics, or website provided.
Language
TypeScript54.6%
MDX41.2%
CSS3.2%
Rust0.5%
Others0.5%