FastGPT/packages/service/core/ai/audio/transcriptions.ts
Archer a3df9ea531
update doc ;perf: model test (#4098)
* perf: extract array

* update doc

* perf: model test

* perf: model test
2025-03-13 19:40:48 +08:00

43 lines
1001 B
TypeScript

import fs from 'fs';
import { getAxiosConfig } from '../config';
import axios from 'axios';
import FormData from 'form-data';
import { getSTTModel } from '../model';
export const aiTranscriptions = async ({
model,
fileStream,
headers
}: {
model: string;
fileStream: fs.ReadStream;
headers?: Record<string, string>;
}) => {
const data = new FormData();
data.append('model', model);
data.append('file', fileStream);
const modelData = getSTTModel(model);
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;
};