Skip to content

Commit e2e4d58

Browse files
committed
fix: Generate prompt
1 parent df44227 commit e2e4d58

File tree

3 files changed

+22
-6
lines changed

3 files changed

+22
-6
lines changed

apps/chat/serializers/chat.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,9 @@ def generate_prompt(self, instance: dict):
171171

172172
message = messages[-1]['content']
173173
q = prompt.replace("{userInput}", message)
174+
q = q.replace("{application_name}",application.name)
175+
q = q.replace("{detail}",application.desc)
176+
174177
messages[-1]['content'] = q
175178

176179
model_exist = QuerySet(Model).filter(

apps/chat/template/generate_prompt_system

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@
5555
## 限制:
5656
1. **严格限制回答范围**:仅回答与角色设定相关的问题。
5757
- 如果用户提问与角色无关,必须使用以下固定格式回复:
58-
“对不起,我只能回答与角色设定相关的问题,您的问题不在服务范围内。”
58+
“对不起,我只能回答与[角色设定]相关的问题,您的问题不在服务范围内。”
5959
- 不得提供任何与角色设定无关的回答。
6060
2. 描述角色在互动过程中需要遵循的限制条件2
6161
3. 描述角色在互动过程中需要遵循的限制条件3

ui/src/views/application/component/GeneratePromptDialog.vue

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
{{ $t('views.application.generateDialog.title') }}
3333
</p>
3434
</el-scrollbar>
35-
<div v-if="answer && !loading && !isStreaming && !showContinueButton">
35+
<div v-if="answer && !loading && !isStreaming && !showContinueButton" class="mt-8">
3636
<el-button type="primary" @click="() => emit('replace', answer)">
3737
{{ $t('views.application.generateDialog.replace') }}
3838
</el-button>
@@ -126,14 +126,22 @@ const promptTemplates = {
126126
INIT_TEMPLATE: `
127127
请根据用户描述生成一个完整的AI角色人设模板:
128128
129+
应用名称:{application_name}
130+
应用描述:{detail}
129131
用户需求:{userInput}
130132
133+
重要说明:
134+
1. 角色设定必须服务于"{application_name}"应用的核心功能
135+
2. 允许用户对角色设定的具体内容进行调整和优化
136+
3. 如果用户要求修改某个技能或部分,在保持应用主题的前提下进行相应调整
137+
131138
请按以下格式生成:
132139
133140
必须严格遵循以下规则:
134141
1. **严格禁止输出解释、前言、额外说明**,只输出最终结果。
135142
2. **严格使用以下格式**,不能缺少标题、不能多出其他段落。
136-
3. **如果用户需求不明确,就忽略用户需求**。
143+
3. **如果用户要求修改角色设定的某个部分,在保持应用核心功能的前提下进行调整**。
144+
4. **如果用户需求与角色设定生成完全无关(如闲聊、其他话题),则忽略用户需求,基于应用信息生成标准角色设定**。
137145
138146
# 角色:
139147
角色概述和主要职责的一句话描述
@@ -174,7 +182,7 @@ const promptTemplates = {
174182
## 限制:
175183
1. **严格限制回答范围**:仅回答与角色设定相关的问题。
176184
- 如果用户提问与角色无关,必须使用以下固定格式回复:
177-
“对不起,我只能回答与角色设定相关的问题,您的问题不在服务范围内。”
185+
“对不起,我只能回答与[角色设定]相关的问题,您的问题不在服务范围内。”
178186
- 不得提供任何与角色设定无关的回答。
179187
2. 描述角色在互动过程中需要遵循的限制条件2
180188
3. 描述角色在互动过程中需要遵循的限制条件3
@@ -200,7 +208,7 @@ const startStreamingOutput = () => {
200208
isPaused.value = false
201209
202210
streamTimer = setInterval(() => {
203-
if (isApiComplete.value && !isPaused.value) {
211+
if (isApiComplete.value && !isPaused.value) {
204212
// 更新显示内容
205213
const currentAnswer = chatMessages.value[chatMessages.value.length - 1]
206214
if (currentAnswer && currentAnswer.role === 'ai') {
@@ -393,10 +401,13 @@ const handleSubmit = (event?: any) => {
393401
if (!event?.ctrlKey && !event?.shiftKey && !event?.altKey && !event?.metaKey) {
394402
// 如果没有按下组合键,则会阻止默认事件
395403
event?.preventDefault()
404+
if (!inputValue.value.trim() || loading.value || isStreaming.value) {
405+
return
406+
}
396407
if (!originalUserInput.value) {
397408
originalUserInput.value = inputValue.value
398409
}
399-
if (isPaused.value || isStreaming.value) {
410+
if (isPaused.value || isStreaming.value) {
400411
return
401412
}
402413
if (inputValue.value) {
@@ -471,6 +482,8 @@ const handleDialogClose = (done: () => void) => {
471482
.catch(() => {
472483
// 点击取消
473484
})
485+
} else {
486+
done()
474487
}
475488
}
476489

0 commit comments

Comments
 (0)