AI 旅行规划器

Stack

Langgraph
MCPuse
Gemini
FastAPI
React

分享

快速开始(推荐)

先决条件

  • Python 3.10 或更高版本
  • Node.js 18 或更高版本
  • Poetry(Python 依赖管理器)

1. 安装 Poetry

curl -sSL https://install.python-poetry.org | python3 -

2. 克隆并初始化

git clone https://github.com/MeirKaD/ai-travel-planner.git
cd ai-travel-planner
chmod +x bootstrap.sh
./bootstrap.sh

就这些!bootstrap 脚本将会:

  • 使用 Poetry 安装所有 Python 依赖
  • 使用 npm 安装所有前端依赖
  • 启动后端与前端服务
  • http://localhost:5173 打开应用

手动设置

后端设置

# Install Python dependencies
poetry install

# Start backend server
poetry run python -m backend.main

前端设置

# Navigate to frontend directory
cd frontend/trip-planner

# Install dependencies
npm install

# Start development server
npm run dev

环境配置

在项目根目录创建一个 .env 文件并填入你的 API Key:

BRIGHT_DATA_API_TOKEN=""
GOOGLE_API_KEY=""
GOOGLE_GENAI_USE_VERTEXAI="False"
SENDGRID_API_KEY=""
FROM_EMAIL=""
TO_EMAIL=""

可用命令

Poetry 命令

# Install dependencies
poetry install

# Add new dependency
poetry add package_name

# Add development dependency
poetry add --group dev package_name

# Run backend
poetry run python -m backend.main

# Run tests
poetry run pytest

# Format code
poetry run black .

# Check code quality
poetry run flake8 .

npm 命令

cd frontend/trip-planner

# Install dependencies
npm install

# Start development server
npm run dev

# Build for production
npm run build

# Preview production build
npm run preview

项目结构

ai-travel-planner/
 backend/
 main.py # FastAPI application
 graph.py # Travel planning workflow
 state.py # Application state management
 frontend/
 trip-planner/ # React application
 pyproject.toml # Poetry configuration
 bootstrap.sh # Quick start script
 README.md

API 端点

  • POST /travel – 规划旅行(包含航班和酒店)
  • GET / – 简单的 Web 界面
  • WS /ws/{thread_id} – 用于实时更新的 WebSocket
  • GET /docs – 交互式 API 文档

功能

  • 智能旅行规划
  • 航班搜索与推荐
  • 带星级评分的酒店搜索
  • 自动化邮件报告
  • 通过 WebSocket 实时更新
  • 响应式 Web 界面
  • 带动画效果的现代化 UI

技术栈

  • Langgraph
  • MCPuse
  • Gemini
  • FastAPI
  • React

故障排查

常见问题

端口已被占用:

# Check what's using port 8000
lsof -i :8000

# Kill the process
kill -9 <PID>

找不到 Poetry:

# Add Poetry to PATH (add to ~/.bashrc or ~/.zshrc)
export PATH="$HOME/.local/bin:$PATH"

依赖无法安装:

# Clear Poetry cache
poetry cache clear pypi --all

# Reinstall dependencies
poetry install --no-cache

开发

添加新依赖

Python 包:

poetry add package_name

开发工具:

poetry add --group dev package_name

前端包:

cd frontend/trip-planner
npm install package_name

代码质量

运行代码格式化与代码检查:

poetry run black .
poetry run flake8 .
poetry run mypy .

测试

poetry run pytest

生产环境部署

后端

# Build and run with Poetry
poetry run uvicorn backend.main:app --host 0.0.0.0 --port 8000

前端

cd frontend/trip-planner
npm run build
# Serve the dist/ folder with your preferred web server

许可证

MIT License – 详情请参见 LICENSE 文件。

支持

如有问题与疑问,请在仓库中创建 issue。