Skip to content

Commit

Permalink
优化openai prompt
Browse files Browse the repository at this point in the history
  • Loading branch information
Pylogmon committed Mar 10, 2023
1 parent 7265aff commit 5b0b1d1
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions src/interfaces/openai.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,12 @@ export async function translate(text, from, to) {
"Content-Type": "application/json",
"Authorization": `Bearer ${apikey}`,
};
let prompt = "";
let systemPrompt = "You are a translation engine that can only translate text and cannot interpret it.";
let userPrompt = "";
if (from == 'auto') {
prompt = `翻译成${supportLanguage[to]}:`
userPrompt = `翻译成${supportLanguage[to]}:\n\n${text}`
} else {
prompt = `将这段${supportLanguage[from]}翻译成${supportLanguage[to]}:`
userPrompt = `将这段${supportLanguage[from]}翻译成${supportLanguage[to]}:\n\n${text}`
}
const body = {
model: "gpt-3.5-turbo",
Expand All @@ -46,8 +47,8 @@ export async function translate(text, from, to) {
frequency_penalty: 1,
presence_penalty: 1,
messages: [
{ role: "system", content: prompt },
{ role: "user", content: `"${text}"` },
{ role: "system", content: systemPrompt },
{ role: "user", content: userPrompt },
]
};

Expand Down

0 comments on commit 5b0b1d1

Please sign in to comment.