feat: 新增语音/图像识别能力(媒体会话、识别接口与路由)
识别只返回文本,不投递、不落库:语音支持 mp3/aac/wav/pcm,WebM 先按文件头识别再转 PCM;图片走 qwen-vl-ocr。新增 /health/ai/asr 与 /health/ai/ocr,登录后按用户限流 20 次/分钟,并对 /health/ai/ 前缀放宽请求体上限。
This commit is contained in:
@@ -6,6 +6,22 @@ import { DBModel } from './models/index.js';
|
||||
import registerRoutes from './routes/index.js';
|
||||
import ResponseUtil from './utils/responseUtil.js';
|
||||
|
||||
// 语音/图片识别走 base64 JSON,单请求体可能达到数 MB;
|
||||
// 只对该前缀放宽解析上限,其余接口维持 1MB,避免全局放大内存占用
|
||||
const MEDIA_ROUTE_PREFIX = '/health/ai/';
|
||||
const DEFAULT_BODY_LIMIT = '1mb';
|
||||
const MEDIA_BODY_LIMIT = '20mb';
|
||||
const defaultBodyParser = bodyParser({
|
||||
jsonLimit: DEFAULT_BODY_LIMIT,
|
||||
formLimit: DEFAULT_BODY_LIMIT,
|
||||
textLimit: DEFAULT_BODY_LIMIT,
|
||||
});
|
||||
const mediaBodyParser = bodyParser({
|
||||
jsonLimit: MEDIA_BODY_LIMIT,
|
||||
formLimit: MEDIA_BODY_LIMIT,
|
||||
textLimit: MEDIA_BODY_LIMIT,
|
||||
});
|
||||
|
||||
class APP {
|
||||
constructor() {
|
||||
this.app = new Koa();
|
||||
@@ -26,7 +42,12 @@ class APP {
|
||||
this.app.proxyIpHeader = "X-Real-IP";
|
||||
|
||||
this.app.use(cors());
|
||||
this.app.use(bodyParser());
|
||||
this.app.use((ctx, next) => {
|
||||
const parser = ctx.path.startsWith(MEDIA_ROUTE_PREFIX)
|
||||
? mediaBodyParser
|
||||
: defaultBodyParser;
|
||||
return parser(ctx, next);
|
||||
});
|
||||
|
||||
this.app.use(async (ctx, next) => {
|
||||
const start = Date.now();
|
||||
|
||||
Reference in New Issue
Block a user