Skip to content

Commit f4bc4eb

Browse files
committed
feat: Improve prompt
1 parent 0c53e31 commit f4bc4eb

File tree

5 files changed

+25
-15
lines changed

5 files changed

+25
-15
lines changed

ui/src/api/application/application.ts

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -206,16 +206,21 @@ const open: (application_id: string, loading?: Ref<boolean>) => Promise<Result<s
206206
}
207207

208208
/**
209-
* 生成优化提示词
210-
*
209+
* 生成提示词
210+
* @param workspace_id
211+
* @param model_id
212+
* @param application_id
213+
* @param data
214+
* @returns
211215
*/
212-
const generate_prompt: (workspace_id:string ,model_id:string, data: any) => Promise<any> = (
216+
const generate_prompt: (workspace_id:string ,model_id:string, application_id:string,data: any) => Promise<any> = (
213217
workspace_id,
214218
model_id,
219+
application_id,
215220
data
216221
) => {
217222
const prefix = (window.MaxKB?.prefix ? window.MaxKB?.prefix : '/admin') + '/api'
218-
return postStream(`${prefix}/workspace/${workspace_id}/application/model/${model_id}/prompt_generate`, data)
223+
return postStream(`${prefix}/workspace/${workspace_id}/application/${application_id}/model/${model_id}/prompt_generate`, data)
219224
}
220225

221226

ui/src/views/application/ApplicationSetting.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -784,7 +784,7 @@ const openAIParamSettingDialog = () => {
784784
785785
const openGeneratePromptDialog = () => {
786786
if (applicationForm.value.model_id) {
787-
GeneratePromptDialogRef.value?.open(applicationForm.value.model_id)
787+
GeneratePromptDialogRef.value?.open(applicationForm.value.model_id, id)
788788
}
789789
}
790790

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

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ const chatMessages = ref<Array<any>>([])
8585
// 原始输入
8686
const originalUserInput = ref<string>('')
8787
const modelID = ref('')
88+
const applicationID = ref('')
8889
const dialogVisible = ref(false)
8990
const inputValue = ref<string>('')
9091
const loading = ref<boolean>(false)
@@ -97,8 +98,8 @@ const promptTemplates = {
9798
9899
请按以下格式生成:
99100
100-
# 角色: 角色名称
101-
角色概述和主要职责的一句话描述
101+
# 角色:
102+
102103
103104
## 目标:
104105
角色的工作目标,如果有多目标可以分点列出,但建议更聚焦1-2个目标
@@ -118,9 +119,12 @@ const promptTemplates = {
118119
119120
120121
## 限制:
121-
描述角色在互动过程中需要遵循的限制条件1
122-
描述角色在互动过程中需要遵循的限制条件2
123-
描述角色在互动过程中需要遵循的限制条件3
122+
1. **严格限制回答范围**:仅回答与角色设定相关的问题。
123+
- 如果用户提问与角色无关,必须使用以下固定格式回复:
124+
“对不起,我只能回答与【角色设定】相关的问题,您的问题不在服务范围内。”
125+
- 不得提供任何与角色设定无关的回答。
126+
2. 描述角色在互动过程中需要遵循的限制条件2
127+
3. 描述角色在互动过程中需要遵循的限制条件3
124128
`,
125129
}
126130
@@ -200,7 +204,7 @@ function generatePrompt(inputValue: any) {
200204
messages: chatMessages.value,
201205
prompt: promptTemplates.INIT_TEMPLATE,
202206
}
203-
generatePromptAPI.generate_prompt(workspaceId, modelID.value, requestData).then((response) => {
207+
generatePromptAPI.generate_prompt(workspaceId, modelID.value, applicationID.value,requestData).then((response) => {
204208
const reader = response.body.getReader()
205209
reader.read().then(getWrite(reader))
206210
})
@@ -226,8 +230,9 @@ const stopChat = () => {
226230
chatMessages.value = []
227231
}
228232
229-
const open = (modelId: string) => {
233+
const open = (modelId: string, applicationId: string) => {
230234
modelID.value = modelId
235+
applicationID.value = applicationId
231236
dialogVisible.value = true
232237
originalUserInput.value = ''
233238
chatMessages.value = []

ui/src/workflow/nodes/ai-chat-node/index.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -439,7 +439,7 @@ const openAIParamSettingDialog = (modelId: string) => {
439439
const GeneratePromptDialogRef = ref<InstanceType<typeof GeneratePromptDialog>>()
440440
const openGeneratePromptDialog = (modelId: string) => {
441441
if (modelId) {
442-
GeneratePromptDialogRef.value?.open(modelId)
442+
GeneratePromptDialogRef.value?.open(modelId, id)
443443
}
444444
}
445445
const replace = (v: any) => {

ui/src/workflow/nodes/intent-classify-node/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ class IntentNode extends AppNode {
66
}
77
}
88

9-
const get_up_index_height = (branch_lsit: Array<any>, index: number) => {
10-
return branch_lsit
9+
const get_up_index_height = (branch_list: Array<any>, index: number) => {
10+
return branch_list
1111
.filter((item, i) => i < index)
1212
.map((item) => item.height + 8)
1313
.reduce((x,y) => x+y, 0)

0 commit comments

Comments
 (0)