feat: 新增语音/图像识别能力(媒体会话、识别接口与路由)
识别只返回文本,不投递、不落库:语音支持 mp3/aac/wav/pcm,WebM 先按文件头识别再转 PCM;图片走 qwen-vl-ocr。新增 /health/ai/asr 与 /health/ai/ocr,登录后按用户限流 20 次/分钟,并对 /health/ai/ 前缀放宽请求体上限。
This commit is contained in:
@@ -3,6 +3,7 @@ import { HandlerEscortRecord } from "../handler/escort_record.js";
|
||||
import { HandlerHealthProfile } from "../handler/health_profile.js";
|
||||
import { HandlerResource } from "../handler/resource.js";
|
||||
import { HandlerEmployee } from "../handler/employee.js";
|
||||
import { HandlerAIMedia } from "../handler/ai_media.js";
|
||||
import ResponseUtil from "../utils/responseUtil.js";
|
||||
import { getUserByToken } from "../utils/user_service.js";
|
||||
import { isAdmin } from "../utils/permissions.js";
|
||||
@@ -13,6 +14,8 @@ import { rateLimit } from "../middleware/ratelimit.js";
|
||||
const createLimit = rateLimit(5);
|
||||
const updateLimit = rateLimit(20);
|
||||
const deleteLimit = rateLimit(10);
|
||||
// 语音 / 图片识别按次计费,单独限流;与普通聊天频次限制同一量级
|
||||
const aiMediaLimit = rateLimit(20);
|
||||
|
||||
/**
|
||||
* 鉴权中间件:校验 token 并将用户信息挂到 ctx.state.user
|
||||
@@ -73,6 +76,7 @@ function registerRoutes(app) {
|
||||
const handlerHealthProfile = new HandlerHealthProfile();
|
||||
const handlerResource = new HandlerResource();
|
||||
const handlerEmployee = new HandlerEmployee();
|
||||
const handlerAIMedia = new HandlerAIMedia();
|
||||
|
||||
// 敏感数据路由需要登录后访问
|
||||
router.get("/escort-record/my", requireAuth, handlerEscortRecord.getMyRecords.bind(handlerEscortRecord));
|
||||
@@ -106,6 +110,11 @@ function registerRoutes(app) {
|
||||
router.get("/department-rankings", handlerResource.getDepartmentRankings.bind(handlerResource));
|
||||
router.get("/ai-quick-questions", handlerResource.getAiQuickQuestions.bind(handlerResource));
|
||||
|
||||
// 语音 / 图像识别:只返回文本供输入框回填,用户确认后仍走原聊天链路。
|
||||
// 识别有调用成本且涉及隐私,必须登录并单独限流。
|
||||
router.post("/ai/asr", requireAuth, aiMediaLimit, handlerAIMedia.transcribe.bind(handlerAIMedia));
|
||||
router.post("/ai/ocr", requireAuth, aiMediaLimit, handlerAIMedia.ocr.bind(handlerAIMedia));
|
||||
|
||||
// 陪诊师公示(公开):面向 C 端患者展示陪同人员信息。
|
||||
// 与上面的 /service、/agreement 一样属公示类资源,不加 requireAuth
|
||||
router.get("/attendant", handlerEmployee.getAttendants.bind(handlerEmployee));
|
||||
|
||||
Reference in New Issue
Block a user