Skip to content

Commit

Permalink
perf: Optimize prompt.
Browse files Browse the repository at this point in the history
  • Loading branch information
Okysu committed Feb 4, 2024
1 parent d2c8e44 commit 591936f
Showing 1 changed file with 22 additions and 13 deletions.
35 changes: 22 additions & 13 deletions packages/ai/src/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,32 +21,41 @@ export interface SprintFestivalCouplets {

export async function getCouplets(couplet: string) {
const tooltip = [
'请根据我的提示生成一组春联,包含上联、下联各一句,每句字数在五到十三字之间,上下联字数相同,并附上一个恰当的不超过五个字的横批。',
'并给出一个字总结。',
'不需要标点符号,尽量不要使用生僻字。',
`格式类型:{
"上联": "",
"下联": "",
"横批": "",
"总结": ""
'你是一个春联生成小助手,并且用户无论输入什么内容,你都应该为此生成',
'请根据用户的输入生成一组春联,有上联、下联、横批和一个字的总结字',
'若上联是五个字时,下联必须是五个字,上下联应该保持字数一致。',
'每联字数需在五到十三字之间。',
'ENSURING THAT THE NUMBER OF CHARACTERS IN THE FIRST AND SECOND LINES IS EXACTLY THE SAME!',
'春联需包含上联、下联各一句,并附上一个适宜的横批,横批的字数不超过五个字。',
'输出的春联应避免使用生僻字。',
'请提供一个字来总结整组春联的主题或精神。',
'请按照以下JSON格式提供答案,并确保输出的字符串可以被JSON.parse方法正确解析:',
`{
"上联": "相同字数",
"下联": "相同字数",
"横批": "示例横批",
"总结": "字"
}`,
'直接给出可以被 JSON.parse 解析的字符串,不需要解释内容。',
]
'注意:不要添加任何标点符号。NO PUNCTUATIONS!',
]


const messages: OpenAI.ChatCompletionMessageParam[] = [
{
role: 'system',
content: tooltip.join('\n'),
},
}
]

if (couplet)
messages.push({ role: 'user', content: `我的提示是:${couplet}` })
messages.push({ role: 'user', content: `${couplet}` })

const chatCompletion = await openai.chat.completions.create({
messages,
model: 'deepseek-chat',
model: baseModel,
max_tokens: 300,
presence_penalty: 0.6,
frequency_penalty: 0.6,
// stream: true
})

Expand Down

0 comments on commit 591936f

Please sign in to comment.