Files
Edu/services/ai/README.md
SpecialX 7474a92e3b feat(p5): messaging, push gateway and AI assistant services
P5 阶段交付物:
- services/msg: 消息通知服务(NestJS)
  - notifications: 发送通知 + ES 全文检索 + search
  - config/elasticsearch.ts: ES Client 单例
  - package.json: 补充 @opentelemetry/sdk-node + exporter-trace-otlp-http
- services/push-gateway: WebSocket 推送网关(Go Gin)
  - internal/hub/hub.go: WebSocket 连接池管理(Register/Unregister/SendToUser)
  - internal/ws/handler.go: JWT 鉴权 + WebSocket 升级 + 内部推送 API
- services/ai: AI 辅助服务(Python FastAPI)
  - /chat + /chat/stream(SSE 流式)
  - /generate/question + /optimize/expression
  - config.py: OpenAI 兼容 API 配置
- packages/shared-proto/proto/msg.proto: NotificationService 契约(send/search)
- packages/shared-proto/proto/ai.proto: AiService 契约(含 stream 方法)
2026-07-08 01:39:02 +08:00

46 lines
1.2 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# AI 网关服务
> 版本0.1P5 骨架)
> 端口3008
## 职责
AI 网关限界上下文Python 实现),统一封装 LLM 调用(多模型路由、重试、限流、成本控制)。
提供辅助出题、表达优化、分层提问等能力。通过 gRPC 查询 content 题库与 data-ana 学情数据。
## 技术栈
- Python 3.12 + FastAPI 0.115
- Pydantic 2 + pydantic-settings
- OpenTelemetryLLM 调用链追踪)
- prometheus-client + structlog
- SSE 流式响应
## 开发
```bash
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 | 日志级别 |