diff --git a/src/apis/trans.js b/src/apis/trans.js
index 3e01d7c..9b5689d 100644
--- a/src/apis/trans.js
+++ b/src/apis/trans.js
@@ -192,25 +192,35 @@ const genOpenAI = ({
to,
url,
key,
+ systemPrompt,
prompt,
model,
temperature,
maxTokens,
}) => {
+ // 兼容历史上作为systemPrompt的prompt,如果prompt中不包含带翻译文本,则添加文本到prompt末尾
+ if (!prompt.includes(INPUT_PLACE_TEXT)) {
+ prompt += `\nSource Text: ${INPUT_PLACE_TEXT}`;
+ }
prompt = prompt
.replaceAll(INPUT_PLACE_FROM, from)
- .replaceAll(INPUT_PLACE_TO, to);
+ .replaceAll(INPUT_PLACE_TO, to)
+ .replaceAll(INPUT_PLACE_TEXT, text);
+ systemPrompt = systemPrompt
+ .replaceAll(INPUT_PLACE_FROM, from)
+ .replaceAll(INPUT_PLACE_TO, to)
+ .replaceAll(INPUT_PLACE_TEXT, text);
const data = {
model,
messages: [
{
role: "system",
- content: prompt,
+ content: systemPrompt,
},
{
role: "user",
- content: text,
+ content: prompt,
},
],
temperature,
@@ -279,6 +289,10 @@ const genClaude = ({
.replaceAll(INPUT_PLACE_FROM, from)
.replaceAll(INPUT_PLACE_TO, to)
.replaceAll(INPUT_PLACE_TEXT, text);
+ systemPrompt = systemPrompt
+ .replaceAll(INPUT_PLACE_FROM, from)
+ .replaceAll(INPUT_PLACE_TO, to)
+ .replaceAll(INPUT_PLACE_TEXT, text);
const data = {
model,
diff --git a/src/config/index.js b/src/config/index.js
index 104c848..f6ae28e 100644
--- a/src/config/index.js
+++ b/src/config/index.js
@@ -527,7 +527,8 @@ 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}.`,
+ prompt: `Translate the following source text from ${INPUT_PLACE_FROM} to ${INPUT_PLACE_TO}. Output translation directly without any additional text.\n\nSource Text: ${INPUT_PLACE_TEXT}\n\nTranslated Text:`,
+ systemPrompt: `You are a professional, authentic machine translation engine. You will be provided with a sentence in ${INPUT_PLACE_FROM}, and your task is to translate it into ${INPUT_PLACE_TO}.`,
temperature: 0,
maxTokens: 256,
fetchLimit: 1,
diff --git a/src/views/Options/Apis.js b/src/views/Options/Apis.js
index eed003e..e8b2b55 100644
--- a/src/views/Options/Apis.js
+++ b/src/views/Options/Apis.js
@@ -237,21 +237,16 @@ function ApiFields({ translator }) {
>
)}
- {translator === OPT_TRANS_CLAUDE && (
- <>
-
- >
- )}
-
{(translator.startsWith(OPT_TRANS_OPENAI) ||
translator === OPT_TRANS_CLAUDE) && (
<>
+