Files
Edu/services/ai
SpecialX 0a71b02e04
Some checks failed
CI / quality-ts (push) Failing after 48s
CI / quality-go (push) Failing after 4s
CI / quality-proto (push) Failing after 2s
CI / deploy (push) Has been skipped
fix: code compliance audit and fix across all services
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.
2026-07-09 17:28:27 +08:00
..

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 流式响应

开发

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 日志级别