DerbSwag/llmops-platform-lab
GitHub: DerbSwag/llmops-platform-lab
一个生产级 LLMOps 基础设施实验室,集成 LLM 网关、RAG 管线、AI 安全防护和全链路可观测性监控,帮助团队快速构建和验证大模型部署架构。
Stars: 0 | Forks: 0
# 🧠 LLMOps 平台实验室
生产级 MLOps/LLMOps 基础设施实验室 — LLM Gateway, RAG Pipeline, AI Security 和 Observability。






## 🏗️ 架构
```
┌─────────────────────────────────────────────────────────────────┐
│ Client / User │
└──────────────────────────────┬──────────────────────────────────┘
│
▼
┌──────────────────────────────────────────────────────────────────┐
│ LLM Gateway (FastAPI) │
│ • API Key Auth • Rate Limiting • Cost Tracking • Routing │
└──────────┬───────────────────┬───────────────────┬───────────────┘
│ │ │
▼ ▼ ▼
┌──────────────────┐ ┌─────────────────┐ ┌─────────────────────────┐
│ AI Security │ │ RAG Service │ │ LLM Backend │
│ • Prompt Guard │ │ • Embeddings │ │ • Ollama (local) │
│ • Input Valid. │ │ • pgvector │ │ • vLLM (GPU) │
│ • PII Filter │ │ • Retrieval │ │ • OpenAI-compatible │
└──────────────────┘ └─────────────────┘ └─────────────────────────┘
│ │ │
└───────────────────┼───────────────────┘
▼
┌──────────────────────────────────────────────────────────────────┐
│ Observability Stack │
│ • Prometheus (metrics) • Grafana (dashboards) • Loki (logs) │
│ • Token cost tracking • Latency P95/P99 • Error rates │
└──────────────────────────────────────────────────────────────────┘
```
```
graph TD
Client[Client / User] --> Gateway[LLM Gateway - FastAPI]
Gateway --> Security[AI Security Layer]
Gateway --> RAG[RAG Service]
Gateway --> LLM[LLM Backend]
Security --> |Prompt Guard, PII Filter| Gateway
RAG --> pgvector[(pgvector)]
LLM --> Ollama[Ollama - Local]
LLM --> vLLM[vLLM - GPU]
Gateway --> Observability[Observability Stack]
Observability --> Prometheus[Prometheus]
Observability --> Grafana[Grafana]
```
## 📁 项目结构
```
llmops-platform-lab/
├── docker-compose.yml # Full stack orchestration
├── gateway/ # LLM Gateway service
│ ├── main.py # FastAPI app (routing, auth, rate limit)
│ ├── security.py # AI Security layer
│ ├── requirements.txt
│ └── Dockerfile
├── rag/ # RAG service
│ ├── main.py # FastAPI app (embed, retrieve, generate)
│ ├── requirements.txt
│ └── Dockerfile
├── monitoring/
│ ├── prometheus.yml # Prometheus config
│ ├── grafana/
│ │ └── dashboards/ # Pre-built dashboards
│ └── alerts.yml # Alert rules
├── docs/
│ ├── AI_SECURITY_CHECKLIST.md
│ └── MLOPS_PIPELINE_SPEC.md
├── .github/workflows/
│ └── ci.yml # CI pipeline
├── .env.example # Config template
└── README.md
```
## 🚀 快速开始
```
# Clone
git clone https://github.com/DerbSwag/llmops-platform-lab.git
cd llmops-platform-lab
# 配置
cp .env.example .env
# 启动所有服务
docker compose up -d
# 访问
# - LLM Gateway: http://localhost:8000/docs
# - RAG Service: http://localhost:8001/docs
# - Grafana: http://localhost:3000 (admin/admin)
# - Prometheus: http://localhost:9090
```
## 🔧 组件
| 服务 | 端口 | 用途 |
|---------|------|---------|
| LLM Gateway | 8000 | API 路由、身份验证、速率限制、成本追踪 |
| RAG Service | 8001 | 文档摄取、嵌入、检索 |
| Ollama | 11434 | 本地 LLM 推理 |
| PostgreSQL + pgvector | 5432 | RAG 的向量存储 |
| Prometheus | 9090 | 指标收集 |
| Grafana | 3000 | 仪表盘与告警 |
## 🔒 AI 安全功能
- ✅ 提示注入检测(模式 + 分类器)
- ✅ 输入验证(长度、编码、格式)
- ✅ 发送至 LLM 前的 PII 过滤
- ✅ API 密钥管理(哈希处理,可轮换)
- ✅ 按密钥的速率限制(令牌桶算法)
- ✅ 响应脱敏
- ✅ 审计日志
完整清单请参阅 [AI 安全检查清单](docs/AI_SECURITY_CHECKLIST.md)。
## 📊 监控与成本控制
- 每个 API 密钥的 Token 使用量(输入/输出 Token)
- 每次请求的成本估算(可配置 $/Token)
- 延迟百分比位数(P50, P95, P99)
- 按类型划分的错误率
- 缓存命中率
- 预算阈值告警
## 📄 文档
- [AI 安全检查清单](docs/AI_SECURITY_CHECKLIST.md) — 基础设施层面的 AI 安全控制
- [MLOps 流水线规范](docs/MLOPS_PIPELINE_SPEC.md) — Pipeline 设计、部署策略、回滚机制
## 🛠️ 技术栈
| 层级 | 技术 |
|-------|-----------|
| 语言 | Python 3.11+ |
| API 框架 | FastAPI |
| LLM 运行时 | Ollama / vLLM |
| 向量数据库 | PostgreSQL + pgvector |
| 嵌入模型 | sentence-transformers |
| 编排工具 | Docker Compose |
| 监控 | Prometheus + Grafana |
| CI/CD | GitHub Actions |
| 安全 | 自定义中间件 + OWASP LLM Top 10 |
## 📄 许可证
MIT
标签:AI-Ready, AI Security, AI基础设施, AI开发框架, AI风险缓解, API Key Auth, API集成, AV绕过, CISA项目, Cost Tracking, DevSecOps, DLL 劫持, Docker, FastAPI, Grafana, Linux系统监控, LLM Gateway, LLMOps, LLM应用开发, MLOps, Monitoring, NIDS, pgvector, PostgreSQL, Python, RAG Pipeline, Rate Limiting, Routing, 上游代理, 人工智能安全, 可观测性, 合规性, 向量数据库, 基础架构, 大模型运维, 大语言模型, 安全运营, 安全防御评估, 实验环境, 容器化, 成本跟踪, 扫描框架, 无后门, 智能路由, 机器学习运维, 检索增强生成, 模型安全, 测试用例, 生产级, 监控, 网关, 自定义请求头, 请求拦截, 逆向工具, 配置错误, 限流, 隐蔽技术, 零日漏洞检测