fix: translation hooks and custom api doc
This commit is contained in:
@@ -236,6 +236,36 @@ async (args) => {
|
||||
};
|
||||
```
|
||||
|
||||
v2.0.6 版后内置默认 prompt,Response 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
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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) 的形式支持。`,
|
||||
|
||||
@@ -1404,7 +1404,7 @@ export class Translator {
|
||||
apisMap,
|
||||
});
|
||||
if (hookResult) {
|
||||
Object.assign(args, ...hookResult);
|
||||
Object.assign(args, hookResult);
|
||||
}
|
||||
} catch (err) {
|
||||
kissLog("transStartHook", err);
|
||||
|
||||
Reference in New Issue
Block a user