feat: support batch langdetect

This commit is contained in:
Gabe
2025-09-27 23:33:33 +08:00
parent fffa448425
commit 867c2209b1
6 changed files with 71 additions and 48 deletions

View File

@@ -782,17 +782,10 @@ export const parseTransRes = async (
* @param {*} param0
* @returns
*/
export const handleTranslate = async ({
texts,
from,
to,
fromLang,
toLang,
langMap,
docInfo,
apiSetting,
usePool,
}) => {
export const handleTranslate = async (
texts = [],
{ from, to, fromLang, toLang, langMap, docInfo, apiSetting, usePool }
) => {
let history = null;
let hisMsgs = [];
const {
@@ -850,3 +843,32 @@ export const handleTranslate = async ({
...apiSetting,
});
};
/**
* Microsoft语言识别聚合及解析
* @param {*} texts
* @returns
*/
export const handleMicrosoftLangdetect = async (texts = []) => {
const token = await msAuth();
const input =
"https://api-edge.cognitive.microsofttranslator.com/detect?api-version=3.0";
const init = {
headers: {
"Content-type": "application/json",
Authorization: `Bearer ${token}`,
},
method: "POST",
body: JSON.stringify(texts.map((text) => ({ Text: text }))),
};
const res = await fetchData(input, init, {
useCache: false,
});
if (Array.isArray(res)) {
return res.map((r) => r.language);
}
return [];
};