Skip to content

Migrate from Google Gemini SDK to Vercel AI SDK#2

Open
code-xpertai[bot] wants to merge 1 commit intomainfrom
migrate-to-vercel-ai-sdk
Open

Migrate from Google Gemini SDK to Vercel AI SDK#2
code-xpertai[bot] wants to merge 1 commit intomainfrom
migrate-to-vercel-ai-sdk

Conversation

@code-xpertai
Copy link
Copy Markdown

@code-xpertai code-xpertai bot commented Mar 18, 2026

概述

将项目从 Google Gemini SDK 迁移到 Vercel AI SDK,实现多模型支持。

变更摘要

核心更改

  • 替换 SDK: google-genaivercel-ai-sdk
  • 多模型支持: 通过 AI Gateway 支持 Anthropic、OpenAI、Google 等模型
  • 配置简化: 新的 config.yaml 格式 (provider/model)

文件变更

文件 操作 说明
src/main.py 重写 使用 Vercel AI SDK 的 @ai.toolai.run()ai.stream_loop()
src/tools.py 简化 保留核心工具,移除 PDF/浏览器依赖
src/config.yaml 更新 新配置格式
pyproject.toml 更新 精简依赖
README.md 更新 新的使用文档

删除的功能

  • PDF 处理 (Gemini File API)
  • Browser-use (浏览器自动化)
  • arXiv 论文搜索
  • SQLite 数据库功能
  • 复杂斜杠命令系统

保留的核心工具

  • read_file - 读取文件
  • list_files - 列出目录
  • edit_file - 编辑文件
  • execute_bash_command - 执行白名单命令
  • run_in_sandbox - Docker 沙箱执行
  • get_current_date_and_time - 获取时间
  • web_search - 网页搜索 (占位)
  • open_url - 获取 URL 内容

使用方式

# 安装依赖
pip install -e .

# 设置 API Key (任选其一)
export AI_GATEWAY_API_KEY="your_key"  # 推荐
export ANTHROPIC_API_KEY="your_key"
export OPENAI_API_KEY="your_key"

# 运行
coding-agent

配置示例

# src/config.yaml
model: "anthropic/claude-sonnet-4.6"  # 或 "openai/gpt-4o", "google/gemini-2.5-pro"
verbose: false

代码统计

  • 删除: ~3600 行
  • 新增: ~570 行
  • 净减少: ~3000 行

注意事项

  • vercel-ai-sdk 目前为实验性 SDK
  • 需要设置 AI_GATEWAY_API_KEY 或提供商 API Key
  • Docker 沙箱功能需要 Docker 运行

- Replace google-genai with vercel-ai-sdk for provider-agnostic support
- Support multiple LLM providers via AI Gateway (Anthropic, OpenAI, Google)
- Simplify codebase by removing PDF processing, browser-use, arXiv tools
- Keep core functionality: file ops, bash commands, Docker sandbox
- Update pyproject.toml with minimal dependencies
- Update README with new configuration instructions
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

0 participants