fix: custom apis
This commit is contained in:
@@ -5,6 +5,37 @@
|
|||||||
如果接口的请求数据和返回数据符合以下规范,
|
如果接口的请求数据和返回数据符合以下规范,
|
||||||
则无需填写 `Request Hook` 或 `Response Hook`。
|
则无需填写 `Request Hook` 或 `Response Hook`。
|
||||||
|
|
||||||
|
|
||||||
|
### 非聚合翻译 (v2.0.9)
|
||||||
|
|
||||||
|
Request body
|
||||||
|
|
||||||
|
```json
|
||||||
|
{
|
||||||
|
"text": "hello", // 需要翻译的文本列表
|
||||||
|
"from":"auto", // 原文语言
|
||||||
|
"to": "zh-CN" // 目标语言
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
Response
|
||||||
|
|
||||||
|
```json
|
||||||
|
{
|
||||||
|
"text": "你好", // 译文
|
||||||
|
"src": "en" // 原文语言
|
||||||
|
}
|
||||||
|
|
||||||
|
// 或者
|
||||||
|
{
|
||||||
|
"text": "你好", // 译文
|
||||||
|
"from": "en" // 原文语言
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
|
### 聚合翻译
|
||||||
|
|
||||||
Request body
|
Request body
|
||||||
|
|
||||||
```json
|
```json
|
||||||
|
|||||||
@@ -589,8 +589,10 @@ const genCloudflareAI = ({ texts, from, to, url, key }) => {
|
|||||||
return { url, body, headers };
|
return { url, body, headers };
|
||||||
};
|
};
|
||||||
|
|
||||||
const genCustom = ({ texts, fromLang, toLang, url, key }) => {
|
const genCustom = ({ texts, fromLang, toLang, url, key, useBatchFetch }) => {
|
||||||
const body = { texts, from: fromLang, to: toLang };
|
const body = useBatchFetch
|
||||||
|
? { texts, from: fromLang, to: toLang }
|
||||||
|
: { text: texts[0], from: fromLang, to: toLang };
|
||||||
const headers = {
|
const headers = {
|
||||||
"Content-type": "application/json",
|
"Content-type": "application/json",
|
||||||
Authorization: `Bearer ${key}`,
|
Authorization: `Bearer ${key}`,
|
||||||
@@ -810,6 +812,8 @@ export const parseTransRes = async (
|
|||||||
history.add(userMsg, hookResult.modelMsg);
|
history.add(userMsg, hookResult.modelMsg);
|
||||||
}
|
}
|
||||||
return hookResult.translations;
|
return hookResult.translations;
|
||||||
|
} else if (Array.isArray(hookResult)) {
|
||||||
|
return hookResult;
|
||||||
}
|
}
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
kissLog("run res hook", err);
|
kissLog("run res hook", err);
|
||||||
@@ -912,7 +916,10 @@ export const parseTransRes = async (
|
|||||||
}
|
}
|
||||||
return parseAIRes(modelMsg?.content, useBatchFetch);
|
return parseAIRes(modelMsg?.content, useBatchFetch);
|
||||||
case OPT_TRANS_CUSTOMIZE:
|
case OPT_TRANS_CUSTOMIZE:
|
||||||
return (res?.translations ?? res)?.map((item) => [item.text, item.src]);
|
if (useBatchFetch) {
|
||||||
|
return (res?.translations ?? res)?.map((item) => [item.text, item.src]);
|
||||||
|
}
|
||||||
|
return [[res.text, res.src || res.from]];
|
||||||
default:
|
default:
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -559,7 +559,6 @@ const defaultApiOpts = {
|
|||||||
},
|
},
|
||||||
[OPT_TRANS_CUSTOMIZE]: {
|
[OPT_TRANS_CUSTOMIZE]: {
|
||||||
...defaultApi,
|
...defaultApi,
|
||||||
url: "https://translate.googleapis.com/translate_a/single?client=gtx&dj=1&dt=t&ie=UTF-8&q={{text}}&sl=en&tl=zh-CN",
|
|
||||||
reqHook: defaultRequestHook,
|
reqHook: defaultRequestHook,
|
||||||
resHook: defaultResponseHook,
|
resHook: defaultResponseHook,
|
||||||
},
|
},
|
||||||
|
|||||||
Reference in New Issue
Block a user