跳转到内容

源码构建

源码构建适合需要在 Server 侧开发调试的场景。

  • Go 1.27+
  • PostgreSQL 17+(需 pgvector 扩展)— 推荐 pgvector/pgvector:pg17 镜像
  • Redis 7+
  • LLM API — Claude 或 OpenAI 兼容接口
终端窗口
git clone https://github.com/rtc-agent/server.git
cd server

使用开发 Docker Compose 启动 PostgreSQL、Redis 等:

终端窗口
# 启动开发依赖(PostgreSQL:15432, Redis:16379, Jaeger, Mock OAuth2 等)
go run main.go dev dependencies start

或手动启动 Docker:

终端窗口
docker compose -f etc/dev/docker-compose.yml up -d

复制配置模板并编辑:

终端窗口
cp etc/config.example.yaml etc/config.local.yaml

编辑 etc/config.local.yaml,至少修改以下字段:

database:
dsn: "postgres://rtc_agent:rtc_agent@localhost:15432/rtc_agent?sslmode=disable"
redis:
addr: "localhost:16379"
llm:
provider: "claude" # 或 "openai"
api_key: "${LLM_API_KEY}" # 通过环境变量注入,启动前 export LLM_API_KEY="your-key"
model: "claude-sonnet-4-20250514"

配置合并机制:Server 启动时自动加载 etc/config.yaml(基线)+ etc/config.local.yaml(覆盖)。config.local.yaml 已在 .gitignore 中,不会被提交。只需写差异项。

🔐 API Key 安全api_key 支持 ${ENV_VAR} 形式引用环境变量,避免明文写入配置文件。启动前通过 export LLM_API_KEY="your-key" 设置即可。

终端窗口
# 构建
go build -o bin/rtc-agent .
# 数据库迁移(首次部署)
./bin/rtc-agent migrate
# 启动服务
./bin/rtc-agent serve

服务启动在 http://localhost:8888

终端窗口
curl http://localhost:8888/healthz
# {"status":"ok"}

Server 启动后,在你的网页中添加 <rtc-agent> 组件:

<script type="module" src="https://cdn.example.com/rtc-agent/index.js"></script>
<rtc-agent></rtc-agent>

详见 Web Component API