Skip to content

Commit 786ebdd

Browse files
committed
fix: improve the prompt to avoid many failed translation cases
1 parent ecb324c commit 786ebdd

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

src/main.js

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,14 +45,19 @@ function translate(query, completion) {
4545
frequency_penalty: 1,
4646
presence_penalty: 1,
4747
};
48+
prompt = `${prompt}:\n\n"${query.text}" =>`;
4849
const isChatGPTModel = ChatGPTModels.indexOf($option.model) > -1;
4950
if (isChatGPTModel) {
5051
body.messages = [
51-
{ role: "system", content: prompt },
52-
{ role: "user", content: `"${query.text}"` },
52+
{
53+
role: "system",
54+
content:
55+
"You are a translation engine that can only translate text and cannot interpret it.",
56+
},
57+
{ role: "user", content: prompt },
5358
];
5459
} else {
55-
body.prompt = `${prompt}:\n\n"${query.text}" =>`;
60+
body.prompt = prompt;
5661
}
5762
(async () => {
5863
const resp = await $http.request({

0 commit comments

Comments
 (0)