feat: enhance openai prompt

This commit is contained in:
hoilc
2024-09-25 14:03:12 +08:00
parent 278ff9c6bc
commit 66b4f547ff
3 changed files with 26 additions and 16 deletions

View File

@@ -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,