一、部署实现AI项目

学习流程

  1. 运行跑通项目
  2. 理解项目中每个服务是干什么的,对应那部分的文件和代码
  3. 改动代码,查看效果
  4. 理解项目的核心技术和实现方式
  5. 整理自己的项目的了解:运用哪些技术,功能如何实现。

让项目跑起来

1. 克隆代码到本地

使用git克隆到本地,或者在github直接点击下载到本地

git clone https://github.com/ljxpython/agent-platform.git

2. 配置环境

安装 python、uv、node、pnpm

# 安装 Python 3.13(https://www.python.org/downloads/)
uv python install 3.13    # 或者通过uv安装
python --version    # 验证

# 安装uv
powershell -c "irm https://astral.sh/uv/install.ps1 | iex"

# 安装node.js 22.x.x (官方下载:https://nodejs.org/ )
node --version

# 安装 pnpm 10.5.1
npm install -g pnpm@10.5.1
pnpm --version

3. 数据库配置

  • 安装 PostgreSQL-16:https://www.postgresql.org/download/windows/ 选择 Windows x86-64 版本
  • 开始菜单打开pgAdmin4图形化界面
    • 右键点击 “Databases” → “Create” → “Database”
      • Database: agent_platform
      • Owner: postgres
    • 右键点击 “Login/Group Roles” → “Create” → “Login/Group Role”
      • Name: agent
      • Password: YourStrongPassword123!
      • Privileges: 勾选 “Can login?” 和 “Superuser”
# 以管理员身份运行命令提示符# 创建数据库
createdb -U postgres agent_platform

# 创建用户
psql -U postgres -c "CREATE USER agent WITH PASSWORD '123456';"
psql -U postgres -c "GRANT ALL PRIVILEGES ON DATABASE agent_platform TO agent;"

# 测试连接
psql -U agent -d agent_platform -h 127.0.0.1
# 输入密码:123456(agent用户密码)# 如果成功,显示:agent_platform=## 输入 \q 退出
# 命令行打开数据库
D:\Tools_Package\PostgreSQL\bin>.\psql -U agent -d agent_platform -h localhost -p 5432
用户 agent 的口令:123456

4. API模型配置

  • 硅基流动API:官方地址:https://cloud.siliconflow.cn/
    • 获取API:左侧菜单「API 密钥」→「新建 API 密钥」→ 复制密钥
  • 修改配置文件:ai-agent-platform\apps\runtime-service\runtime_service\conf\settings.yaml
    # YAML settings template
    default:
      default_model_id: siliconflow
      models:
        siliconflow:
          model_provider: openai
          model: Qwen/Qwen2.5-7B-Instruct
          base_url: https://api.siliconflow.cn/v1
          api_key: sk-前面申请的API_KEY
    
    test:
      default_model_id: siliconflow
    
    production:
      default_model_id: siliconflow
    

5. 配置文件修改

  • 配置文件路径:ai-agent-platform\apps
服务配置文件改动点
runtime-service (8123)runtime_service/conf/settings.yaml填写硅基流动 API Key,default_model_id: siliconflow(参考API配置)
runtime_service/.envAPP_ENV=test
MODEL_ID=
platform-api (2025)platform-api/.envDATABASE_URL=postgresql+psycop://agent:我的密码123456@127.0.0.1:5432/agent_platform
interaction-data-service (8090)interaction-data-service/.env保持默认
platform-web-vue (3000)platform-web-vue/.envVITE_PLATFORM_API_URL=http://localhost:2025
runtime-web (3001)runtime-web/.envNEXT_PUBLIC_API_URL=http://localhost:8123`

6. 启动服务

  • 启动顺序:runtime-service → interaction-data-service → platform-api → 前端(不同的窗口)
# runtime-service
cd apps/runtime-service && uv sync
uv run langgraph dev --config runtime_service/langgraph.json --port 8123 --no-browser

# interaction-data-service
cd apps/interaction-data-service && uv sync
uv run uvicorn main:app --host 0.0.0.0 --port 8090 --reload

# platform-api
cd apps/platform-api && uv sync
uv run uvicorn main:app --host 0.0.0.0 --port 2025

# platform-web-vue
cd apps/platform-web-vue && pnpm install
pnpm dev

# runtime-web
cd apps/runtime-web && pnpm install
pnpm dev --port 3001

7. 常见问题

  • langgraph.json编码错误:文件包含中文,GBK 编码读取失败。建议直接删除中文。(yaml文件编码必须用 UTF-8 无 BOM,否则 LangGraph 读取报错)
  • 验证API是否可用:
    • 命令行测试 api_key是否有效

      # 在powershell中运行
      $apiKey = "sk-你新复制的密钥"
      
      $body = @{
          model = "deepseek-chat"
          messages = @(
              @{role = "user"; content = "你好"}
          )
      } | ConvertTo-Json
      
      Invoke-RestMethod -Uri "https://api.deepseek.com/v1/chat/completions" `
          -Method Post `
          -Headers @{Authorization = "Bearer $apiKey"; "Content-Type" = "application/json"} `
          -Body $body
          
       # 预期返回正常回复内容
      
    • 重启 runtime-service,访问http://127.0.0.1:8123/internal/capabilities/models。

      • 正确输出:{“count”:1,“models”:[{“model_id”:“siliconflow”,“display_name”:“siliconflow”,“is_default”:true}]}

8. 一键运行脚本

cd D:\Desktop\ai-agent-platform

# 启动
.\scripts\dev-up.sh

# 健康检查
.\scripts\check-health.sh

# 停止
.\scripts\dev-down.sh
Logo

Agent 垂直技术社区,欢迎活跃、内容共建。

更多推荐