feat: add more openai translator
This commit is contained in:
@@ -10,6 +10,8 @@ import {
|
|||||||
OPT_TRANS_BAIDU,
|
OPT_TRANS_BAIDU,
|
||||||
OPT_TRANS_TENCENT,
|
OPT_TRANS_TENCENT,
|
||||||
OPT_TRANS_OPENAI,
|
OPT_TRANS_OPENAI,
|
||||||
|
OPT_TRANS_OPENAI_2,
|
||||||
|
OPT_TRANS_OPENAI_3,
|
||||||
OPT_TRANS_GEMINI,
|
OPT_TRANS_GEMINI,
|
||||||
OPT_TRANS_CLOUDFLAREAI,
|
OPT_TRANS_CLOUDFLAREAI,
|
||||||
OPT_TRANS_CUSTOMIZE,
|
OPT_TRANS_CUSTOMIZE,
|
||||||
@@ -244,6 +246,8 @@ export const apiTranslate = async ({
|
|||||||
isSame = text === trText;
|
isSame = text === trText;
|
||||||
break;
|
break;
|
||||||
case OPT_TRANS_OPENAI:
|
case OPT_TRANS_OPENAI:
|
||||||
|
case OPT_TRANS_OPENAI_2:
|
||||||
|
case OPT_TRANS_OPENAI_3:
|
||||||
trText = res?.choices?.map((item) => item.message.content).join(" ");
|
trText = res?.choices?.map((item) => item.message.content).join(" ");
|
||||||
isSame = text === trText;
|
isSame = text === trText;
|
||||||
break;
|
break;
|
||||||
|
|||||||
@@ -9,6 +9,8 @@ import {
|
|||||||
OPT_TRANS_BAIDU,
|
OPT_TRANS_BAIDU,
|
||||||
OPT_TRANS_TENCENT,
|
OPT_TRANS_TENCENT,
|
||||||
OPT_TRANS_OPENAI,
|
OPT_TRANS_OPENAI,
|
||||||
|
OPT_TRANS_OPENAI_2,
|
||||||
|
OPT_TRANS_OPENAI_3,
|
||||||
OPT_TRANS_GEMINI,
|
OPT_TRANS_GEMINI,
|
||||||
OPT_TRANS_CLOUDFLAREAI,
|
OPT_TRANS_CLOUDFLAREAI,
|
||||||
OPT_TRANS_CUSTOMIZE,
|
OPT_TRANS_CUSTOMIZE,
|
||||||
@@ -317,6 +319,8 @@ export const genTransReq = ({ translator, text, from, to }, apiSetting) => {
|
|||||||
switch (translator) {
|
switch (translator) {
|
||||||
case OPT_TRANS_DEEPL:
|
case OPT_TRANS_DEEPL:
|
||||||
case OPT_TRANS_OPENAI:
|
case OPT_TRANS_OPENAI:
|
||||||
|
case OPT_TRANS_OPENAI_2:
|
||||||
|
case OPT_TRANS_OPENAI_3:
|
||||||
case OPT_TRANS_GEMINI:
|
case OPT_TRANS_GEMINI:
|
||||||
case OPT_TRANS_CLOUDFLAREAI:
|
case OPT_TRANS_CLOUDFLAREAI:
|
||||||
case OPT_TRANS_NIUTRANS:
|
case OPT_TRANS_NIUTRANS:
|
||||||
@@ -346,6 +350,8 @@ export const genTransReq = ({ translator, text, from, to }, apiSetting) => {
|
|||||||
case OPT_TRANS_TENCENT:
|
case OPT_TRANS_TENCENT:
|
||||||
return genTencent(args);
|
return genTencent(args);
|
||||||
case OPT_TRANS_OPENAI:
|
case OPT_TRANS_OPENAI:
|
||||||
|
case OPT_TRANS_OPENAI_2:
|
||||||
|
case OPT_TRANS_OPENAI_3:
|
||||||
return genOpenAI(args);
|
return genOpenAI(args);
|
||||||
case OPT_TRANS_GEMINI:
|
case OPT_TRANS_GEMINI:
|
||||||
return genGemini(args);
|
return genGemini(args);
|
||||||
|
|||||||
@@ -104,6 +104,8 @@ export const OPT_TRANS_NIUTRANS = "NiuTrans";
|
|||||||
export const OPT_TRANS_BAIDU = "Baidu";
|
export const OPT_TRANS_BAIDU = "Baidu";
|
||||||
export const OPT_TRANS_TENCENT = "Tencent";
|
export const OPT_TRANS_TENCENT = "Tencent";
|
||||||
export const OPT_TRANS_OPENAI = "OpenAI";
|
export const OPT_TRANS_OPENAI = "OpenAI";
|
||||||
|
export const OPT_TRANS_OPENAI_2 = "OpenAI2";
|
||||||
|
export const OPT_TRANS_OPENAI_3 = "OpenAI3";
|
||||||
export const OPT_TRANS_GEMINI = "Gemini";
|
export const OPT_TRANS_GEMINI = "Gemini";
|
||||||
export const OPT_TRANS_CLOUDFLAREAI = "CloudflareAI";
|
export const OPT_TRANS_CLOUDFLAREAI = "CloudflareAI";
|
||||||
export const OPT_TRANS_CUSTOMIZE = "Custom";
|
export const OPT_TRANS_CUSTOMIZE = "Custom";
|
||||||
@@ -121,6 +123,8 @@ export const OPT_TRANS_ALL = [
|
|||||||
OPT_TRANS_DEEPLX,
|
OPT_TRANS_DEEPLX,
|
||||||
OPT_TRANS_NIUTRANS,
|
OPT_TRANS_NIUTRANS,
|
||||||
OPT_TRANS_OPENAI,
|
OPT_TRANS_OPENAI,
|
||||||
|
OPT_TRANS_OPENAI_2,
|
||||||
|
OPT_TRANS_OPENAI_3,
|
||||||
OPT_TRANS_GEMINI,
|
OPT_TRANS_GEMINI,
|
||||||
OPT_TRANS_CLOUDFLAREAI,
|
OPT_TRANS_CLOUDFLAREAI,
|
||||||
OPT_TRANS_CUSTOMIZE,
|
OPT_TRANS_CUSTOMIZE,
|
||||||
@@ -254,6 +258,12 @@ export const OPT_LANGS_SPECIAL = {
|
|||||||
[OPT_TRANS_OPENAI]: new Map(
|
[OPT_TRANS_OPENAI]: new Map(
|
||||||
OPT_LANGS_FROM.map(([key, val]) => [key, val.split(" - ")[0]])
|
OPT_LANGS_FROM.map(([key, val]) => [key, val.split(" - ")[0]])
|
||||||
),
|
),
|
||||||
|
[OPT_TRANS_OPENAI_2]: new Map(
|
||||||
|
OPT_LANGS_FROM.map(([key, val]) => [key, val.split(" - ")[0]])
|
||||||
|
),
|
||||||
|
[OPT_TRANS_OPENAI_3]: new Map(
|
||||||
|
OPT_LANGS_FROM.map(([key, val]) => [key, val.split(" - ")[0]])
|
||||||
|
),
|
||||||
[OPT_TRANS_GEMINI]: new Map(
|
[OPT_TRANS_GEMINI]: new Map(
|
||||||
OPT_LANGS_FROM.map(([key, val]) => [key, val.split(" - ")[0]])
|
OPT_LANGS_FROM.map(([key, val]) => [key, val.split(" - ")[0]])
|
||||||
),
|
),
|
||||||
@@ -464,6 +474,14 @@ const defaultCustomApi = {
|
|||||||
fetchLimit: DEFAULT_FETCH_LIMIT,
|
fetchLimit: DEFAULT_FETCH_LIMIT,
|
||||||
fetchInterval: DEFAULT_FETCH_INTERVAL,
|
fetchInterval: DEFAULT_FETCH_INTERVAL,
|
||||||
};
|
};
|
||||||
|
const defaultOpenaiApi = {
|
||||||
|
url: "https://api.openai.com/v1/chat/completions",
|
||||||
|
key: "",
|
||||||
|
model: "gpt-4",
|
||||||
|
prompt: `You will be provided with a sentence in ${INPUT_PLACE_FROM}, and your task is to translate it into ${INPUT_PLACE_TO}.`,
|
||||||
|
fetchLimit: 1,
|
||||||
|
fetchInterval: 500,
|
||||||
|
};
|
||||||
export const DEFAULT_TRANS_APIS = {
|
export const DEFAULT_TRANS_APIS = {
|
||||||
[OPT_TRANS_GOOGLE]: {
|
[OPT_TRANS_GOOGLE]: {
|
||||||
url: "https://translate.googleapis.com/translate_a/single",
|
url: "https://translate.googleapis.com/translate_a/single",
|
||||||
@@ -507,14 +525,9 @@ export const DEFAULT_TRANS_APIS = {
|
|||||||
fetchLimit: DEFAULT_FETCH_LIMIT,
|
fetchLimit: DEFAULT_FETCH_LIMIT,
|
||||||
fetchInterval: DEFAULT_FETCH_INTERVAL,
|
fetchInterval: DEFAULT_FETCH_INTERVAL,
|
||||||
},
|
},
|
||||||
[OPT_TRANS_OPENAI]: {
|
[OPT_TRANS_OPENAI]: defaultOpenaiApi,
|
||||||
url: "https://api.openai.com/v1/chat/completions",
|
[OPT_TRANS_OPENAI_2]: defaultOpenaiApi,
|
||||||
key: "",
|
[OPT_TRANS_OPENAI_3]: defaultOpenaiApi,
|
||||||
model: "gpt-4",
|
|
||||||
prompt: `You will be provided with a sentence in ${INPUT_PLACE_FROM}, and your task is to translate it into ${INPUT_PLACE_TO}.`,
|
|
||||||
fetchLimit: 1,
|
|
||||||
fetchInterval: 500,
|
|
||||||
},
|
|
||||||
[OPT_TRANS_GEMINI]: {
|
[OPT_TRANS_GEMINI]: {
|
||||||
url: "https://generativelanguage.googleapis.com/v1/models",
|
url: "https://generativelanguage.googleapis.com/v1/models",
|
||||||
key: "",
|
key: "",
|
||||||
|
|||||||
@@ -11,6 +11,8 @@ import {
|
|||||||
OPT_TRANS_BAIDU,
|
OPT_TRANS_BAIDU,
|
||||||
OPT_TRANS_TENCENT,
|
OPT_TRANS_TENCENT,
|
||||||
OPT_TRANS_OPENAI,
|
OPT_TRANS_OPENAI,
|
||||||
|
OPT_TRANS_OPENAI_2,
|
||||||
|
OPT_TRANS_OPENAI_3,
|
||||||
OPT_TRANS_GEMINI,
|
OPT_TRANS_GEMINI,
|
||||||
OPT_TRANS_CLOUDFLAREAI,
|
OPT_TRANS_CLOUDFLAREAI,
|
||||||
OPT_TRANS_CUSTOMIZE,
|
OPT_TRANS_CUSTOMIZE,
|
||||||
@@ -133,7 +135,7 @@ function ApiFields({ translator }) {
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
const buildinTranslators = [
|
const builtinTranslators = [
|
||||||
OPT_TRANS_MICROSOFT,
|
OPT_TRANS_MICROSOFT,
|
||||||
OPT_TRANS_DEEPLFREE,
|
OPT_TRANS_DEEPLFREE,
|
||||||
OPT_TRANS_BAIDU,
|
OPT_TRANS_BAIDU,
|
||||||
@@ -143,6 +145,8 @@ function ApiFields({ translator }) {
|
|||||||
const mulkeysTranslators = [
|
const mulkeysTranslators = [
|
||||||
OPT_TRANS_DEEPL,
|
OPT_TRANS_DEEPL,
|
||||||
OPT_TRANS_OPENAI,
|
OPT_TRANS_OPENAI,
|
||||||
|
OPT_TRANS_OPENAI_2,
|
||||||
|
OPT_TRANS_OPENAI_3,
|
||||||
OPT_TRANS_GEMINI,
|
OPT_TRANS_GEMINI,
|
||||||
OPT_TRANS_CLOUDFLAREAI,
|
OPT_TRANS_CLOUDFLAREAI,
|
||||||
OPT_TRANS_NIUTRANS,
|
OPT_TRANS_NIUTRANS,
|
||||||
@@ -164,7 +168,7 @@ function ApiFields({ translator }) {
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<Stack spacing={3}>
|
<Stack spacing={3}>
|
||||||
{!buildinTranslators.includes(translator) && (
|
{!builtinTranslators.includes(translator) && (
|
||||||
<>
|
<>
|
||||||
<TextField
|
<TextField
|
||||||
size="small"
|
size="small"
|
||||||
@@ -191,7 +195,8 @@ function ApiFields({ translator }) {
|
|||||||
</>
|
</>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
{(translator === OPT_TRANS_OPENAI || translator === OPT_TRANS_GEMINI) && (
|
{(translator.startsWith(OPT_TRANS_OPENAI) ||
|
||||||
|
translator === OPT_TRANS_GEMINI) && (
|
||||||
<>
|
<>
|
||||||
<TextField
|
<TextField
|
||||||
size="small"
|
size="small"
|
||||||
|
|||||||
Reference in New Issue
Block a user