fix: translation hooks and custom api doc

This commit is contained in:
Gabe
2025-11-03 18:42:47 +08:00
parent fd014a1d34
commit 4b19902e5c
4 changed files with 40 additions and 4 deletions

View File

@@ -236,6 +236,36 @@ async (args) => {
};
```
v2.0.6 版后内置默认 promptResponse Hook 可以简化为:
```js
async (args) => {
const url = args.url;
const method = "POST";
const headers = {
"Content-type": "application/json",
Authorization: `Bearer ${args.key}`,
};
const body = {
model: "tencent/Hunyuan-MT-7B", // 或 args.model
messages: [
{
role: "system",
content: args.defaultNobatchPrompt, // 或 args.nobatchPrompt
},
{
role: "user",
content: args.defaultNobatchUserPrompt, // 或 args.nobatchUserPrompt
},
],
temperature: 0,
max_tokens: 20480,
};
return { url, body, headers, method };
};
```
Response Hook
```js

View File

@@ -694,7 +694,13 @@ export const genTransReq = async ({ reqHook, ...args }) => {
try {
interpreter.run(`exports.reqHook = ${reqHook}`);
const hookResult = await interpreter.exports.reqHook(
{ ...args, defaultSystemPrompt, defaultSubtitlePrompt },
{
...args,
defaultSystemPrompt,
defaultSubtitlePrompt,
defaultNobatchPrompt,
defaultNobatchUserPrompt,
},
{
url,
body,

View File

@@ -526,9 +526,9 @@ export const I18N = {
zh_TW: `1.其中 BuiltinAI 為瀏覽器內建AI翻譯目前僅 Chrome 138 以上版本支援。`,
},
about_api_2: {
zh: `2、大部分AI接口都与OpenAI兼容因此选择添加OpenAI类型即可。`,
zh: `2、大部分AI接口都与OpenAI兼容因此选择添加OpenAI类型即可。It should be noted that Prompt has two types: batch translation and nobatch translation. Not all interfaces support batch translation.`,
en: `2. Most AI interfaces are compatible with OpenAI, so just choose to add the OpenAI type.`,
zh_TW: `2.大部分AI介面都與OpenAI相容因此選擇新增OpenAI類型即可。`,
zh_TW: `2.大部分AI介面都與OpenAI相容因此選擇新增OpenAI類型即可。要注意的是Prompt分聚合翻譯和非聚合翻譯兩種不是所有介面都支援聚合翻譯。`,
},
about_api_3: {
zh: `3、暂未列出的接口理论上都可以通过自定义接口 (Custom) 的形式支持。`,

View File

@@ -1404,7 +1404,7 @@ export class Translator {
apisMap,
});
if (hookResult) {
Object.assign(args, ...hookResult);
Object.assign(args, hookResult);
}
} catch (err) {
kissLog("transStartHook", err);