diff --git a/custom-api_v2.md b/custom-api_v2.md index 9f370e9..c11bbee 100644 --- a/custom-api_v2.md +++ b/custom-api_v2.md @@ -2,6 +2,8 @@ ## 谷歌翻译接口 +> 此接口不支持聚合 + URL ``` @@ -29,6 +31,8 @@ async ({ res }) => { ## Ollama +> 此示例为支持聚合的模型类(要支持上下文,需进一步改动) + * 注意 ollama 启动参数需要添加环境变量 `OLLAMA_ORIGINS=*` * 检查环境变量生效命令:`systemctl show ollama | grep OLLAMA_ORIGINS` @@ -80,11 +84,11 @@ async (args) => { const method = "POST"; const headers = { "Content-type": "application/json" }; const body = { - model: "gemma3", + model: "gemma3", // v2.0.2 版后此处可填 args.model messages: [ { role: "system", - content: args.defaultSystemPrompt, + content: args.defaultSystemPrompt, // 或者 args.systemPrompt }, { role: "user", @@ -150,3 +154,53 @@ async ({ res, parseAIRes, }) => { return { translations }; }; ``` + + +## 硅基流动 + +> 此示例为不支持聚合模型类,支持聚合的模型类参考上面 Ollama 的写法 + +URL + +``` +https://api.siliconflow.cn/v1/chat/completions +``` + +Request 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", // v2.0.2 版后此处可填 args.model + messages: [ + { + role: "system", + content: + "You are a professional, authentic machine translation engine.", + }, + { + role: "user", + content: `Translate the following source text from to ${args.to}. Output translation directly without any additional text.\n\nSource Text: ${args.texts[0]}\n\nTranslated Text:`, + }, + ], + temperature: 0, + max_tokens: 20480, + }; + + return { url, body, headers, method }; +}; +``` + +Response Hook + +```js +async ({ res }) => { + return { translations: [res?.choices?.[0]?.message?.content || ""] }; +}; +``` diff --git a/src/views/Options/Apis.js b/src/views/Options/Apis.js index 93709d8..5f2c9d9 100644 --- a/src/views/Options/Apis.js +++ b/src/views/Options/Apis.js @@ -263,7 +263,7 @@ function ApiFields({ apiSlug, isUserApi, deleteApi }) { /> )} - {API_SPE_TYPES.ai.has(apiType) && ( + {(API_SPE_TYPES.ai.has(apiType) || apiType === OPT_TRANS_CUSTOMIZE) && ( <>