Files
FastGPT/packages/service/core/ai/audio/transcriptions.ts
Archer 2fcf421672 add model test log (#4272)
* sync collection

* remove lock

* add model test log

* update ui

* update log

* fix: channel test

* preview chunk ui

* test model ux

* test model log

* perf: dataset selector

* fix: system plugin auth

* update nextjs
2025-03-27 10:05:31 +08:00

47 lines
1.1 KiB
TypeScript

import fs from 'fs';
import { getAxiosConfig } from '../config';
import axios from 'axios';
import FormData from 'form-data';
import { getSTTModel } from '../model';
import { STTModelType } from '@fastgpt/global/core/ai/model.d';
export const aiTranscriptions = async ({
model: modelData,
fileStream,
headers
}: {
model: STTModelType;
fileStream: fs.ReadStream;
headers?: Record<string, string>;
}) => {
if (!modelData) {
return Promise.reject('no model');
}
const data = new FormData();
data.append('model', modelData.model);
data.append('file', fileStream);
const aiAxiosConfig = getAxiosConfig();
const { data: result } = await axios<{ text: string }>({
method: 'post',
...(modelData.requestUrl
? { url: modelData.requestUrl }
: {
baseURL: aiAxiosConfig.baseUrl,
url: '/audio/transcriptions'
}),
headers: {
Authorization: modelData.requestAuth
? `Bearer ${modelData.requestAuth}`
: aiAxiosConfig.authorization,
...data.getHeaders(),
...headers
},
data: data
});
return result;
};