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
1 change: 1 addition & 0 deletions ui/src/locales/lang/en-US/views/application-workflow.ts
Original file line number Diff line number Diff line change
Expand Up @@ -341,6 +341,7 @@ You are a master of problem optimization, adept at accurately inferring user int
label: 'IntentNode',
text: 'Match user questions with user-defined intent classifications',
other: 'other',
error2: 'Repeated intent',
placeholder: 'Please choose a classification option',
classify: {
label: 'Intent classify',
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 appears to be an issue with the key name in classify: label is repeated, resulting in a warning due to duplicate keys when parsing JSON data. This can lead to inconsistent behavior and bugs if it isn't addressed properly.

Recommendation:

Rename the label within the classify object to avoid duplicates. Here's an updated version:

const formOptions = [
  {
    label: 'IntentNode',
    text: 'Match user questions with user-defined intent classifications',
    other: 'other',
    error2: 'Repeated intent',
    placeholder: 'Please choose a classification option',
    classify: {
      description: 'This field describes how intents are being classified.',
    },
  },
];

Additional Suggestions:

  1. Consistent Object Key Naming: Ensure that all objects in the array have consistent naming patterns for easy maintenance and readability.

  2. Error Handling: Consider adding more detailed handling for potential errors, such as validation checks before submitting user input.

  3. Dynamic UI Elements: If you plan to dynamically generate these options based on some logic (e.g., based on user roles), ensure those elements are managed correctly.

  4. API Integration: If this code will integrate with an API, consider any specific requirements or best practices for sending structured data.

By addressing these points, you can improve the robustness and maintainability of your code.

Expand Down
1 change: 1 addition & 0 deletions ui/src/locales/lang/zh-CN/views/application-workflow.ts
Original file line number Diff line number Diff line change
Expand Up @@ -341,6 +341,7 @@ export default {
label: '意图识别',
text: '将用户问题与用户预设的意图分类进行匹配',
other: '其他',
error2: '意图重复',
placeholder: '请选择分类项',
classify: {
label: '意图分类',
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 code looks mostly clean and well-structured. However, here are some minor improvements and points to consider:

  • The error2 key appears to be an error message or hint related to intent duplication, but there is no corresponding error handling or user feedback mechanism in this context. Consider adding such mechanisms if needed.
  • You might want to add a comma after "其他" to better align with the rest of the code.

Overall, the code is ready for production use without significant issues.

Expand Down
1 change: 1 addition & 0 deletions ui/src/locales/lang/zh-Hant/views/application-workflow.ts
Original file line number Diff line number Diff line change
Expand Up @@ -334,6 +334,7 @@ export default {
label: '意圖識別',
text: '將用戶問題與用戶預設的意圖分類進行匹配',
other: '其他',
error2: '意圖重複',
placeholder: '請選擇分類項',
classify: {
label: '意圖分類',
Expand Down
20 changes: 15 additions & 5 deletions ui/src/workflow/nodes/intent-classify-node/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -90,10 +90,6 @@
/>
</el-form-item>
<el-form-item
:rules="{
required: true,
trigger: 'change',
}"
>
<template #label>
<div class="flex-between">
Expand All @@ -113,6 +109,14 @@
v-for="(item, index) in form_data.branch"
v-resize="(wh: any) => resizeBranch(wh, item, index)"
:key="item.id"
>
<el-form-item
:prop="`branch.${index}.content`"
:rules="{
message: $t('views.applicationWorkflow.nodes.intentNode.classify.placeholder'),
trigger: 'change',
required: true,
}"
>
<el-row class="mb-8" :gutter="12" align="middle">
<el-col :span="21">
Expand All @@ -138,6 +142,7 @@
</el-button>
</el-col>
</el-row>
</el-form-item>
</div>
</div>
</el-form-item>
Expand Down Expand Up @@ -326,10 +331,15 @@ const IntentClassifyNodeFormRef = ref<FormInstance>()
const modelOptions = ref<any>(null)

const validate = () => {

return Promise.all([
nodeCascaderRef.value ? nodeCascaderRef.value.validate() : Promise.resolve(''),
IntentClassifyNodeFormRef.value?.validate(),
]).catch((err: any) => {
]).then(() => {
if (form_data.value.branch.length != new Set(form_data.value.branch.map((item: any) => item.content)).size) {
throw t('views.applicationWorkflow.nodes.intentNode.error2')
}
}).catch((err: any) => {
return Promise.reject({ node: props.nodeModel, errMessage: err })
})
}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Some areas for improvement:

  1. Duplicate Code: v-for loops with the same structure can be simplified. However, since Vue's data-binding works on individual elements within these loops, you might still need them as separate components/elements.

    <div key="item.id" v-for="(item, index) in form_data.branch">
        <!-- Item content -->
        
        
    </div>
  2. Validation Logic: The existing code checks if there are duplicate values inside the array of branches. But it could do so more directly using Vue.js' reactivity system and error handling.

    Instead:

    const uniqueValues = new Set(form_data.value.branch.map(item => item.content));
    if (uniqueValues.size !== form_data.value.branch.length) {
        throw new Error(t('views.applicationWorkflow.nodes.intentNode.error2'));
    }

    This ensures that each branch should have unique names or contents without needing explicit checking per element.

  3. Code Cleanup:

    Remove unnecessary comments and organize related blocks logically.

    For example, consolidating validation logic into one place simplifies readability.

  4. Error Messages:

    Consider providing clearer contextual messages to users which would help diagnose what went wrong if an error occurs during processing or submission.

const validate = async () => {
  try {
    await nodeCascaderRef.value.validate()
    await intent_classify_form_ref.validate()

    // Check for uniqueness
    const unique_values = new Set(form_data.value.branch.map((item: any) =>
      item.content || item.label // Handle cases where label exists but content doesn't
    )
    if (unique_values.size !== form_data.value.branch.length) {
      throw new Error(t('views.applicationWorkflow.nodes.intentNode.error2'))
    }

  } catch (error) {
    return Promise.reject({ 
      node: props.nodeModel, 
      errorMessage: error.message || t('views.applicationWorkflow.common.validationFailed') 
    })
  }
}
  1. Consistency:

    Ensure consistent use of camelCase for variable naming convention within the code block as they're already snake_case elsewhere.

These changes aim to make the form validation process more efficient and user-friendly while maintaining clarity.

Expand Down
Loading