This commit is contained in:
Archer
2023-11-10 11:14:08 +08:00
committed by GitHub
parent 0a0fe31d3c
commit d91551e6be
17 changed files with 257 additions and 26 deletions

View File

@@ -0,0 +1,48 @@
import type { NextApiRequest, NextApiResponse } from 'next';
import { jsonRes } from '@fastgpt/service/common/response';
import { authCert } from '@fastgpt/service/support/permission/auth/common';
import { withNextCors } from '@fastgpt/service/common/middle/cors';
import { getUploadModel } from '@fastgpt/service/common/file/upload/multer';
import fs from 'fs';
import { getAIApi } from '@fastgpt/service/core/ai/config';
const upload = getUploadModel({
maxSize: 2
});
export default withNextCors(async function handler(req: NextApiRequest, res: NextApiResponse<any>) {
try {
const { teamId, tmbId } = await authCert({ req, authToken: true });
const { files } = await upload.doUpload(req, res);
const file = files[0];
if (!file) {
throw new Error('file not found');
}
const ai = getAIApi();
const result = await ai.audio.transcriptions.create({
file: fs.createReadStream(file.path),
model: 'whisper-1'
});
jsonRes(res, {
data: result.text
});
} catch (err) {
console.log(err);
jsonRes(res, {
code: 500,
error: err
});
}
});
export const config = {
api: {
bodyParser: false
}
};