feat: support keypick for customize API
This commit is contained in:
@@ -84,7 +84,7 @@ const genGoogle = ({ text, from, to, url, key }) => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const genGoogle2 = ({ text, from, to, url, key }) => {
|
const genGoogle2 = ({ text, from, to, url, key }) => {
|
||||||
const body = JSON.stringify([[ [text], from, to ], "wt_lib"]);
|
const body = JSON.stringify([[[text], from, to], "wt_lib"]);
|
||||||
const init = {
|
const init = {
|
||||||
method: "POST",
|
method: "POST",
|
||||||
headers: {
|
headers: {
|
||||||
@@ -182,7 +182,8 @@ const genTencent = ({ text, from, to }) => {
|
|||||||
const data = {
|
const data = {
|
||||||
header: {
|
header: {
|
||||||
fn: "auto_translation",
|
fn: "auto_translation",
|
||||||
client_key: "browser-chrome-110.0.0-Mac OS-df4bd4c5-a65d-44b2-a40f-42f34f3535f2-1677486696487"
|
client_key:
|
||||||
|
"browser-chrome-110.0.0-Mac OS-df4bd4c5-a65d-44b2-a40f-42f34f3535f2-1677486696487",
|
||||||
},
|
},
|
||||||
type: "plain",
|
type: "plain",
|
||||||
model_category: "normal",
|
model_category: "normal",
|
||||||
@@ -198,8 +199,9 @@ const genTencent = ({ text, from, to }) => {
|
|||||||
const init = {
|
const init = {
|
||||||
headers: {
|
headers: {
|
||||||
"Content-Type": "application/json",
|
"Content-Type": "application/json",
|
||||||
"user-agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/110.0.0.0 Safari/537.36",
|
"user-agent":
|
||||||
"referer": "https://transmart.qq.com/zh-CN/index"
|
"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/110.0.0.0 Safari/537.36",
|
||||||
|
referer: "https://transmart.qq.com/zh-CN/index",
|
||||||
},
|
},
|
||||||
method: "POST",
|
method: "POST",
|
||||||
body: JSON.stringify(data),
|
body: JSON.stringify(data),
|
||||||
@@ -280,7 +282,16 @@ const genOpenAI = ({
|
|||||||
return [url, init];
|
return [url, init];
|
||||||
};
|
};
|
||||||
|
|
||||||
const genGemini = ({ text, from, to, url, key, systemPrompt, userPrompt, model }) => {
|
const genGemini = ({
|
||||||
|
text,
|
||||||
|
from,
|
||||||
|
to,
|
||||||
|
url,
|
||||||
|
key,
|
||||||
|
systemPrompt,
|
||||||
|
userPrompt,
|
||||||
|
model,
|
||||||
|
}) => {
|
||||||
url = url
|
url = url
|
||||||
.replaceAll(INPUT_PLACE_MODEL, model)
|
.replaceAll(INPUT_PLACE_MODEL, model)
|
||||||
.replaceAll(INPUT_PLACE_KEY, key);
|
.replaceAll(INPUT_PLACE_KEY, key);
|
||||||
@@ -297,13 +308,13 @@ const genGemini = ({ text, from, to, url, key, systemPrompt, userPrompt, model }
|
|||||||
system_instruction: {
|
system_instruction: {
|
||||||
parts: {
|
parts: {
|
||||||
text: systemPrompt,
|
text: systemPrompt,
|
||||||
}
|
},
|
||||||
},
|
},
|
||||||
contents: {
|
contents: {
|
||||||
parts: {
|
parts: {
|
||||||
text: userPrompt,
|
text: userPrompt,
|
||||||
}
|
},
|
||||||
}
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
const init = {
|
const init = {
|
||||||
@@ -364,7 +375,17 @@ const genClaude = ({
|
|||||||
return [url, init];
|
return [url, init];
|
||||||
};
|
};
|
||||||
|
|
||||||
const genOllama = ({ text, from, to, think,url, key, systemPrompt, userPrompt,model }) => {
|
const genOllama = ({
|
||||||
|
text,
|
||||||
|
from,
|
||||||
|
to,
|
||||||
|
think,
|
||||||
|
url,
|
||||||
|
key,
|
||||||
|
systemPrompt,
|
||||||
|
userPrompt,
|
||||||
|
model,
|
||||||
|
}) => {
|
||||||
systemPrompt = systemPrompt
|
systemPrompt = systemPrompt
|
||||||
.replaceAll(INPUT_PLACE_FROM, from)
|
.replaceAll(INPUT_PLACE_FROM, from)
|
||||||
.replaceAll(INPUT_PLACE_TO, to)
|
.replaceAll(INPUT_PLACE_TO, to)
|
||||||
@@ -469,6 +490,11 @@ export const genTransReq = ({ translator, text, from, to }, apiSetting) => {
|
|||||||
case OPT_TRANS_OLLAMA_2:
|
case OPT_TRANS_OLLAMA_2:
|
||||||
case OPT_TRANS_OLLAMA_3:
|
case OPT_TRANS_OLLAMA_3:
|
||||||
case OPT_TRANS_NIUTRANS:
|
case OPT_TRANS_NIUTRANS:
|
||||||
|
case OPT_TRANS_CUSTOMIZE:
|
||||||
|
case OPT_TRANS_CUSTOMIZE_2:
|
||||||
|
case OPT_TRANS_CUSTOMIZE_3:
|
||||||
|
case OPT_TRANS_CUSTOMIZE_4:
|
||||||
|
case OPT_TRANS_CUSTOMIZE_5:
|
||||||
args.key = keyPick(translator, args.key, keyMap);
|
args.key = keyPick(translator, args.key, keyMap);
|
||||||
break;
|
break;
|
||||||
case OPT_TRANS_DEEPLX:
|
case OPT_TRANS_DEEPLX:
|
||||||
@@ -481,7 +507,7 @@ export const genTransReq = ({ translator, text, from, to }, apiSetting) => {
|
|||||||
case OPT_TRANS_GOOGLE:
|
case OPT_TRANS_GOOGLE:
|
||||||
return genGoogle(args);
|
return genGoogle(args);
|
||||||
case OPT_TRANS_GOOGLE2:
|
case OPT_TRANS_GOOGLE2:
|
||||||
return genGoogle2(args);
|
return genGoogle2(args);
|
||||||
case OPT_TRANS_MICROSOFT:
|
case OPT_TRANS_MICROSOFT:
|
||||||
return genMicrosoft(args);
|
return genMicrosoft(args);
|
||||||
case OPT_TRANS_DEEPL:
|
case OPT_TRANS_DEEPL:
|
||||||
|
|||||||
@@ -24,6 +24,10 @@ import {
|
|||||||
OPT_TRANS_OLLAMA_2,
|
OPT_TRANS_OLLAMA_2,
|
||||||
OPT_TRANS_OLLAMA_3,
|
OPT_TRANS_OLLAMA_3,
|
||||||
OPT_TRANS_CUSTOMIZE,
|
OPT_TRANS_CUSTOMIZE,
|
||||||
|
OPT_TRANS_CUSTOMIZE_2,
|
||||||
|
OPT_TRANS_CUSTOMIZE_3,
|
||||||
|
OPT_TRANS_CUSTOMIZE_4,
|
||||||
|
OPT_TRANS_CUSTOMIZE_5,
|
||||||
OPT_TRANS_NIUTRANS,
|
OPT_TRANS_NIUTRANS,
|
||||||
URL_KISS_PROXY,
|
URL_KISS_PROXY,
|
||||||
URL_NIUTRANS_REG,
|
URL_NIUTRANS_REG,
|
||||||
@@ -182,6 +186,11 @@ function ApiFields({ translator }) {
|
|||||||
OPT_TRANS_OLLAMA_2,
|
OPT_TRANS_OLLAMA_2,
|
||||||
OPT_TRANS_OLLAMA_3,
|
OPT_TRANS_OLLAMA_3,
|
||||||
OPT_TRANS_NIUTRANS,
|
OPT_TRANS_NIUTRANS,
|
||||||
|
OPT_TRANS_CUSTOMIZE,
|
||||||
|
OPT_TRANS_CUSTOMIZE_2,
|
||||||
|
OPT_TRANS_CUSTOMIZE_3,
|
||||||
|
OPT_TRANS_CUSTOMIZE_4,
|
||||||
|
OPT_TRANS_CUSTOMIZE_5,
|
||||||
];
|
];
|
||||||
|
|
||||||
const keyHelper =
|
const keyHelper =
|
||||||
|
|||||||
Reference in New Issue
Block a user