Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions ui/src/views/application/component/GeneratePromptDialog.vue
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ const promptTemplates = {
1. **严格禁止输出解释、前言、额外说明**,只输出最终结果。
2. **严格使用以下格式**,不能缺少标题、不能多出其他段落。
3. **如果用户要求修改角色设定的某个部分,在保持应用核心功能的前提下进行调整**。
4. **如果用户需求与角色设定生成完全无关(如闲聊、其他话题),则忽略用户需求,基于应用信息生成标准角色设定**。
4. **如果用户需求与角色设定生成完全无关(如闲聊、其他话题),则主要依据应用信息生成标准角色设定,但不完全忽略用户输入,可从中提取有价值的辅助信息(如领域背景、语气风格等)作为次要参考**。

# 角色:
角色概述和主要职责的一句话描述
Expand Down Expand Up @@ -391,7 +391,7 @@ function generatePrompt(inputValue: any) {
// 重新生成点击
const reAnswerClick = () => {
if (originalUserInput.value) {
generatePrompt('结果不满意,请按照格式,重新生成')
generatePrompt(`上一次回答不满意。请针对原始问题"${originalUserInput.value}"并结合对话记录,严格按照格式规范重新生成。`)
}
}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are no significant issues with the code provided. However, I have some minor suggestions for improvement:

Optimizations:

  1. Improve Prompt Structure: Add a more descriptive title to the promptTemplates section, indicating what it contains.

Updated Code snippet:

# 角色设定:
角色概述和主要职责的一句话描述(请根据具体需要填写)

// 重置按钮点击事件处理函数
const reAnswerClick = () => {
  if (originalUserInput.value) {
-    generatePrompt('结果不满意,请按照格式,重新生成')
+    generatePrompt(
      `上一次回答不满意。请针对原始问题 "${originalUserInput.value}" 并结合对话记录,严格按照格式规范重新生成。`
    )
  }
}

Final Result:

After these improvements, the code is concise yet retains its intended functionality. The prompt template now includes a brief description, and the re-answer click event logic has been updated to include feedback about previous responses and dialogue history.

Expand Down
19 changes: 12 additions & 7 deletions ui/src/views/chat-log/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ import { loadSharedApi } from '@/utils/dynamics-api/shared-api'
import { Permission } from '@/utils/permission/type'
import { hasPermission } from '@/utils/permission'
import { PermissionConst, RoleConst } from '@/utils/permission/data'

const route = useRoute()

const apiType = computed(() => {
Expand Down Expand Up @@ -354,17 +354,22 @@ const filter = ref<any>({
min_trample: 0,
comparer: 'and',
})
const postKnowledgeHandler = (knowledgeList: Array<any>) => {
const postKnowledgeHandler = (knowledgeList: Array<any>) => {
return knowledgeList.filter(item => {
if (apiType.value === 'workspace') {
return hasPermission([RoleConst.WORKSPACE_MANAGE.getWorkspaceRole(),
new Permission("KNOWLEDGE_DOCUMENT:READ+EDIT").getWorkspacePermissionWorkspaceManageRole,
new Permission("KNOWLEDGE_DOCUMENT:READ+EDIT").getWorkspaceResourcePermission('KNOWLEDGE', item.id)], 'OR')
if (item.resource_type === 'folder') {
return true
}
if (item.resource_type === 'knowledge') {
return hasPermission([RoleConst.WORKSPACE_MANAGE.getWorkspaceRole(),
new Permission("KNOWLEDGE_DOCUMENT:READ+EDIT").getWorkspacePermissionWorkspaceManageRole,
new Permission("KNOWLEDGE_DOCUMENT:READ+EDIT").getWorkspaceResourcePermission('KNOWLEDGE', item.id)], 'OR')
}
} else if (apiType.value === 'systemManage') {
return hasPermission([RoleConst.ADMIN, PermissionConst.RESOURCE_KNOWLEDGE_DOCUMENT_EDIT],'OR')
}
})
})

}
function filterChange(val: string) {
if (val === 'clear') {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The provided code has several areas that may require attention or improvement:

Irregularities/Missing Code:

  • Missing closing braces in some functions, such as filter and postKnowledgeHandler.
  • Misleading comments indicating incorrect permissions or resources.

Potential Issues:

  • The use of new Permission(...) is redundant since Permission seems already defined with these properties.
  • The logic to filter items does not handle resource_type correctly for folders; all types should be returned unless otherwise stated.

Optimization Suggestions:

  1. Refactor if Statements: Clean up the logic within if statements to reduce complexity and improve readability.
  2. Use Template Literals for String Interpolation: Replace inline strings with template literals for better readability and maintainability.

Here's an improved version of the code following these guidelines:

const filter = ref({
  min_trample: 0,
  comparer: 'and',
});

// Refine postKnowledgeHandler function
function postKnowledgeHandler(knowledgeList: Array<any>): Array<any> {
  return knowledgeList.filter((item): boolean => {
    if (apiType.value === 'workspace') {
      // Ensure only non-folder items meet the permission criteria
      return (
        item.resource_type !== 'folder' &&
        hasPermission([
          PermissionConst.WORKSPACE_MANAGE.getWorkspaceRole(),
          new Permission("KNOWLEDGE_DOCUMENT:READ+EDIT").getWorkspacePermission('WORKSPACE'),
          new Permission("KNOWLEDGE_DOCUMENT:READ+EDIT").getWorkspaceResourcePermission('KNOWLEDGE', item.id),
        ])
      );
    } else if (apiType.value === 'systemManage') {
      return hasPermission([RoleConst.ADMIN, PermissionConst.RESOURCE_KNOWLEDGE_DOCUMENT_EDIT], 'OR');
    }
  });
}

function filterChange(val: string) {
  if (val === 'clear') {
    // Clear filtering logic here if needed
  }
}

By addressing these points, you can enhance the clarity, efficiency, and accuracy of the codebase, contributing to its robustness and performance.

Expand Down
Loading