@@ -192,25 +192,35 @@ const genOpenAI = ({
|
|||||||
to,
|
to,
|
||||||
url,
|
url,
|
||||||
key,
|
key,
|
||||||
|
systemPrompt,
|
||||||
prompt,
|
prompt,
|
||||||
model,
|
model,
|
||||||
temperature,
|
temperature,
|
||||||
maxTokens,
|
maxTokens,
|
||||||
}) => {
|
}) => {
|
||||||
|
// 兼容历史上作为systemPrompt的prompt,如果prompt中不包含带翻译文本,则添加文本到prompt末尾
|
||||||
|
if (!prompt.includes(INPUT_PLACE_TEXT)) {
|
||||||
|
prompt += `\nSource Text: ${INPUT_PLACE_TEXT}`;
|
||||||
|
}
|
||||||
prompt = prompt
|
prompt = prompt
|
||||||
.replaceAll(INPUT_PLACE_FROM, from)
|
.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 = {
|
const data = {
|
||||||
model,
|
model,
|
||||||
messages: [
|
messages: [
|
||||||
{
|
{
|
||||||
role: "system",
|
role: "system",
|
||||||
content: prompt,
|
content: systemPrompt,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
role: "user",
|
role: "user",
|
||||||
content: text,
|
content: prompt,
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
temperature,
|
temperature,
|
||||||
@@ -279,6 +289,10 @@ const genClaude = ({
|
|||||||
.replaceAll(INPUT_PLACE_FROM, from)
|
.replaceAll(INPUT_PLACE_FROM, from)
|
||||||
.replaceAll(INPUT_PLACE_TO, to)
|
.replaceAll(INPUT_PLACE_TO, to)
|
||||||
.replaceAll(INPUT_PLACE_TEXT, text);
|
.replaceAll(INPUT_PLACE_TEXT, text);
|
||||||
|
systemPrompt = systemPrompt
|
||||||
|
.replaceAll(INPUT_PLACE_FROM, from)
|
||||||
|
.replaceAll(INPUT_PLACE_TO, to)
|
||||||
|
.replaceAll(INPUT_PLACE_TEXT, text);
|
||||||
|
|
||||||
const data = {
|
const data = {
|
||||||
model,
|
model,
|
||||||
|
|||||||
@@ -527,7 +527,8 @@ const defaultOpenaiApi = {
|
|||||||
url: "https://api.openai.com/v1/chat/completions",
|
url: "https://api.openai.com/v1/chat/completions",
|
||||||
key: "",
|
key: "",
|
||||||
model: "gpt-4",
|
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,
|
temperature: 0,
|
||||||
maxTokens: 256,
|
maxTokens: 256,
|
||||||
fetchLimit: 1,
|
fetchLimit: 1,
|
||||||
|
|||||||
@@ -237,21 +237,16 @@ function ApiFields({ translator }) {
|
|||||||
</>
|
</>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
{translator === OPT_TRANS_CLAUDE && (
|
|
||||||
<>
|
|
||||||
<TextField
|
|
||||||
size="small"
|
|
||||||
label={"SYSTEM PROMPT"}
|
|
||||||
name="systemPrompt"
|
|
||||||
value={systemPrompt}
|
|
||||||
onChange={handleChange}
|
|
||||||
/>
|
|
||||||
</>
|
|
||||||
)}
|
|
||||||
|
|
||||||
{(translator.startsWith(OPT_TRANS_OPENAI) ||
|
{(translator.startsWith(OPT_TRANS_OPENAI) ||
|
||||||
translator === OPT_TRANS_CLAUDE) && (
|
translator === OPT_TRANS_CLAUDE) && (
|
||||||
<>
|
<>
|
||||||
|
<TextField
|
||||||
|
size="small"
|
||||||
|
label={"SYSTEM PROMPT"}
|
||||||
|
name="systemPrompt"
|
||||||
|
value={systemPrompt}
|
||||||
|
onChange={handleChange}
|
||||||
|
/>
|
||||||
<TextField
|
<TextField
|
||||||
size="small"
|
size="small"
|
||||||
label={"Temperature"}
|
label={"Temperature"}
|
||||||
|
|||||||
Reference in New Issue
Block a user