餐厅评论分析器

一款通过模型上下文协议(MCP)连接餐厅评论数据库的AI代理,支持自然语言交互查询与分析。

  • by UlasArslannn
  • Python
  • 本地部署
  • 更新于
在 GitHub 查看 UlasArslannn/RAG-MCP

使用说明

🍕 RAG-MCP——基于人工智能的餐厅评论分析器

一个连接到 餐厅评论数据库 通过 模型上下文协议(MCP),允许您使用自然语言与您的数据聊天。问以下问题 “人们怎么看披萨?” 并获得智能、上下文感知的答案。

🏗️ 建筑

┌─────────────────────────────────────────────────────────┐
│                    docker compose up                     │
│                                                          │
│  ┌───────────────┐  ┌───────────────┐  ┌──────────────┐ │
│  │  MCP Server    │  │  FastAPI App   │  │    Ollama    │ │
│  │  (SSE)         │  │  (Chat API)    │  │   (LLM)     │ │
│  │  Port 8000     │◄─│  Port 8001     │─►│  Port 11434 │ │
│  │  SQLite DB     │  │  LlamaIndex    │  │  llama3.2   │ │
│  └───────────────┘  └───────────────┘  └──────────────┘ │
└─────────────────────────────────────────────────────────┘
成分 说明
MCP服务器 (scripts/new_server.py通过SSE访问SQLite数据库。 add_comment have的常用口语形式 get_comments 提供他们的工具。
FastAPI应用程序 (scripts/main.pyLlamaIndex 使用 FunctionAgent 处理用户消息,必要时调用 MCP 工具。
奥拉玛 llama3.2 通过运行模型,它可以理解自然语言并产生反应。
抓取 (scripts/scraping.py使用Selenium从Google地图中提取餐厅评论(本地使用)。

📁 项目结构

RAG-MCP/
├── scripts/
│   ├── new_server.py      # MCP Server (SQLite + SSE)
│   ├── main.py            # FastAPI Chat API
│   ├── agent_utils.py     # LLM & Agent konfigürasyonu
│   ├── server.py          # LangChain RAG server (CLI)
│   ├── vector.py          # ChromaDB vektör veritabanı
│   └── scraping.py        # Google Maps yorum scraper
├── tests/
│   ├── conftest.py        # Test fixtures
│   ├── test_mcp_server.py # DB operasyon testleri
│   └── test_api.py        # FastAPI endpoint testleri
├── Dockerfile
├── docker-compose.yml
├── pyproject.toml         # Python bağımlılıkları (uv)
├── requirements.txt       # LangChain bağımlılıkları
├── sql.py                 # Örnek veri ekleme scripti
└── reviews.db             # SQLite veritabanı

🐳 使用Docker安装(推荐)

只需一个命令即可启动项目 - 您无需安装Python,Ollama或任何依赖项。

要求

  • Docker 桌面版 必须安装并运行
  • 英语 4GB 可用内存 (LLM模式)
  • 首次运行时下载 ~2GB(llama3.2 型号)

步骤1:克隆仓库

git clone https://github.com/UlasArslannn/RAG-MCP.git
cd RAG-MCP

步骤2:使用Docker Compose启动

docker compose up --build

按此命令顺序:

  1. ✅ Python Docker 映像
  2. ✅ 建立所有依赖
  3. ✅ 启动服务并 llama3.2 印度模式
  4. ✅ 启动 MCP 服务器(端口 8000)
  5. ✅ 启动 FastAPI Chat API(端口 8001)

步骤3:开始使用

当所有服务都准备好了:

服务 URL
💬 聊天API(Swagger UI) http://localhost:8001/docs
🔧 MCP服务器 http://localhost:8000/sse
🤖 奥拉玛 http://localhost:11434

要向 Chat API 发送消息:

curl -X POST http://localhost:8001/chat \
  -H "Content-Type: application/json" \
  -d '{"message": "Veritabanındaki tüm yorumları göster"}'

或者从Swagger用户界面:http://localhost:8001/docs → POST/聊天 → 试试看

步骤4:停止

docker compose down

如果您还想删除数据库数据:

docker compose down -v

💻 本地安装(无Docker)

如果您想直接在计算机上运行 Docker,而不是:

要求

安装

# 1. Repoyu klonlayın
git clone https://github.com/UlasArslannn/RAG-MCP.git
cd RAG-MCP

# 2. Bağımlılıkları kurun
uv sync

# 3. Ollama'yı başlatın ve modeli indirin
ollama pull llama3.2

# 4. Örnek verileri ekleyin
uv run python sql.py

# 5. MCP Server'ı başlatın (Terminal 1)
uv run python scripts/new_server.py --server_type=sse

# 6. FastAPI'yi başlatın (Terminal 2)
uv run python scripts/main.py

🧪 测试器

# Testleri çalıştırın
uv run pytest tests/ -v

# Coverage ile çalıştırın
uv run pytest tests/ -v --cov=scripts --cov-report=term-missing

测试场景

测试文件 测试是什么 需要吗?
test_mcp_server.py 创建数据库,添加/读取评论,过滤,自定义字符❌ 不。
test_api.py FastAPI终端,验证,CORS❌ 不。

⚙️ 环境变量

Docker Compose 会自动设置这些变量。在本地开发中使用默认值:

变量 Default 说明
MCP_SERVER_URL http://127.0.0.1:8000/sse MCP服务器SSE端点
OLLAMA_HOST http://localhost:11434 API 地址。
LLM_MODEL llama3.2 要使用的LLM模式
DB_PATH (proje kökü)/reviews.db SQLite数据库路径

🔄 CI/CD(GitHub操作)

每个push和pull请求都会自动运行:

Push/PR → 🔍 Lint (ruff) → 🧪 Test (pytest) → 🐳 Docker Build

📝 API终点

方法 终点 说明
GET / 健康检查
POST /chat 向 AI Agent 发送消息
POST /reset 重置你的谈话历史。

POST/聊天

// Request
{
  "message": "En yüksek puanlı yorumları göster",
  "verbose": false
}

// Response
{
  "response": "İşte en yüksek puanlı yorumlar:\n1. Alice (5/5): Margherita pizza was absolutely perfect!...",
  "tool_calls": []
}

📄 许可证

MIT License — 详情 许可证 看看档案。