Skip to content

Commit 6c4b019

Browse files
committed
feat: support custom prompts
1 parent d59b77f commit 6c4b019

File tree

2 files changed

+24
-4
lines changed

2 files changed

+24
-4
lines changed

src/info.json

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,19 +15,19 @@
1515
"type": "text",
1616
"title": "API URL",
1717
"defaultValue": "https://api.openai.com",
18-
"desc": "如果您的网络环境需要代理才能访问 OpenAI API, 可在这里修改为反代 API 的地址,默认为 https://api.openai.com"
18+
"desc": "可选项。如果您的网络环境需要代理才能访问 OpenAI API, 可在这里修改为反代 API 的地址,默认为 https://api.openai.com"
1919
},
2020
{
2121
"identifier": "deploymentName",
2222
"type": "text",
2323
"title": "Dep. Name",
24-
"desc": "如果您使用的是 Azure OpenAI Service,需要填写对应的 deployment ID"
24+
"desc": "可选项。如果您使用的是 Azure OpenAI Service,需要填写对应的 deployment ID"
2525
},
2626
{
2727
"identifier": "apiKeys",
2828
"type": "text",
2929
"title": "API KEY",
30-
"desc": "可以用英文逗号分割多个 API KEY 以实现额度加倍及负载均衡"
30+
"desc": "必填项。可以用英文逗号分割多个 API KEY 以实现额度加倍及负载均衡"
3131
},
3232
{
3333
"identifier": "model",
@@ -68,6 +68,18 @@
6868
"value": "text-davinci-002"
6969
}
7070
]
71+
},
72+
{
73+
"identifier": "customSystemPrompt",
74+
"type": "text",
75+
"title": "Sys PPT",
76+
"desc": "可选项。自定义 System Prompt;必须开启明文显示才可输入中文"
77+
},
78+
{
79+
"identifier": "customUserPrompt",
80+
"type": "text",
81+
"title": "User PPT",
82+
"desc": "可选项。自定义 User Prompt,输入内容会自动拼接在句尾"
7183
}
7284
]
7385
}

src/main.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,14 @@ function generatePrompts(query) {
9999
* }}
100100
*/
101101
function buildRequestBody(model, isChatGPTModel, query) {
102-
const { systemPrompt, userPrompt } = generatePrompts(query);
102+
const { customSystemPrompt, customUserPrompt } = $option;
103+
const { systemPrompt, userPrompt } = customSystemPrompt || customUserPrompt
104+
? {
105+
systemPrompt: customSystemPrompt || "You are ChatGPT, a large language model trained by OpenAI. Follow the user's instructions carefully.",
106+
userPrompt: `${customUserPrompt}:\n\n"${query.text}"`,
107+
}
108+
: generatePrompts(query);
109+
103110
const standardBody = {
104111
model,
105112
temperature: 0,
@@ -108,6 +115,7 @@ function buildRequestBody(model, isChatGPTModel, query) {
108115
frequency_penalty: 1,
109116
presence_penalty: 1,
110117
};
118+
111119
if (isChatGPTModel) {
112120
return {
113121
...standardBody,

0 commit comments

Comments
 (0)