mirror of
https://github.com/labring/FastGPT.git
synced 2025-07-22 12:20:34 +00:00

* 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
47 lines
1.1 KiB
TypeScript
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;
|
|
};
|