NestJS (6 services): implement @RequirePermission decorator with SetMetadata+Reflector, register APP_GUARD globally, fix as assertions to type guards, add explicit return types, fix import type for express, fix /metrics implicit any, replace native Error with ApplicationError, remove typeorm remnants, register LifecycleService. teacher-bff: add logger, ApplicationError, GlobalErrorFilter, forward real userId to downstream, log downstream failures, migrate health controller to shared/health. Go (2 services): interface to any, doc comments, CORS dev whitelist, JWT secret fail-fast, push-gateway internal API auth, metrics and readyz endpoints, remove dead code. Python (2 services): lifespan return type, dev_mode to bool, data-ana APIRouter, ai POST body model, ClickHouse async wrapping.
AI 网关服务
版本:0.1(P5 骨架) 端口:3008
职责
AI 网关限界上下文(Python 实现),统一封装 LLM 调用(多模型路由、重试、限流、成本控制)。 提供辅助出题、表达优化、分层提问等能力。通过 gRPC 查询 content 题库与 data-ana 学情数据。
技术栈
- Python 3.12 + FastAPI 0.115
- Pydantic 2 + pydantic-settings
- OpenTelemetry(LLM 调用链追踪)
- prometheus-client + structlog
- SSE 流式响应
开发
uv sync
uv run uvicorn src.ai.main:app --reload --port 3008
API
| 方法 | 路径 | 说明 |
|---|---|---|
| GET | /healthz | 健康检查 |
| POST | /chat | LLM 聊天接口 |
| POST | /chat/stream | 流式聊天(SSE) |
| POST | /generate/question | 生成题目 |
| POST | /optimize/expression | 优化表达 |
| GET | /metrics | Prometheus 指标 |
环境变量
| 变量 | 默认值 | 说明 |
|---|---|---|
| port | 3008 | 服务端口 |
| openai_api_key | - | OpenAI API 密钥 |
| anthropic_api_key | - | Anthropic API 密钥 |
| otel_endpoint | http://localhost:4318 | OpenTelemetry OTLP 端点 |
| log_level | info | 日志级别 |