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
5 changes: 3 additions & 2 deletions ui/src/locales/lang/en-US/views/document.ts
Original file line number Diff line number Diff line change
Expand Up @@ -171,8 +171,9 @@ export default {
},
feishu: {
selectDocument: 'Select Document',
tip1: 'Only documents and tables are supported. Documents will be segmented based on titles, and tables will be converted to Markdown format before segmentation.',
tip1: 'Supports document and table types such as Feishu documents, TXT, Markdown, PDF, DOCX, HTML, XLS, XLSX, CSV, ZIP Feishu files. Documents will be segmented according to titles, and tables will be converted to Markdown format before segmentation.',
tip2: 'The system does not store the original document. Before importing the document, it is recommended to standardize the document segmentation markers.',
allCheck: 'Select All'
allCheck: 'Select All',
errorMessage1: 'Please select a document'
}
}
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

There appear to be a few potential improvements and corrections in the provided code:

  1. Typography Correction:
    The tip1 text has been edited for better readability and consistency. The original sentence mentions "Feishu documents" while using it both capitalized and lowercase.

  2. Code Formatting:
    Ensure consistent spacing between curly braces {} and other punctuation marks around identifiers.

  3. Comments:
    Consider adding comments explaining the purpose of each function or key within the object literal.

  4. String Concatenation:
    Use template literals (\ at the end) for multiple-line strings for improved clarity and conciseness.

Here's a revised version of the code with these suggestions applied:

export default {
  feishu: {
    selectDocument: 'Select Document',
    tip1: `
      Supports document and table types such as Feishu documents, TXT,
      Markdown, PDF, DOCX, HTML, XLS, XLSX, CSV, ZIP (Feishu files).
      
      Documents will be segmented according to their titles,
      and tables will be converted to Markdown format before segmentation.
    `,
    tip2: 'The system does not store the original document. Before importing the document, it is recommended to standardize the document segmentation markers.',
    allCheck: 'Select All',
    errorMessage1: 'Please select a document'
  }
}

These changes make the code more readable and maintainable.

5 changes: 3 additions & 2 deletions ui/src/locales/lang/zh-CN/views/document.ts
Original file line number Diff line number Diff line change
Expand Up @@ -168,8 +168,9 @@ export default {
},
feishu: {
selectDocument: '选择文档',
tip1: '仅支持文档和表格类型,文档会根据标题分段,表格会转为Markdown格式后再分段。',
tip1: '支持文档和表格类型飞书文档、支持TXT、Markdown、PDF、DOCX、HTML、XLS、XLSX、CSV、ZIP飞书文件,文档会根据标题分段,表格会转为Markdown格式后再分段。',
tip2: '系统不存储原始文档,导入文档前,建议规范文档的分段标识。',
allCheck: '全选'
allCheck: '全选',
errorMessage1: '请选择文档'
}
}
11 changes: 6 additions & 5 deletions ui/src/locales/lang/zh-Hant/views/document.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export default {
cancelGenerateQuestion: '取消生成問題',
cancelVectorization: '取消向量化',
cancelGenerate: '取消生成',
export: '匯出',
export: '匯出'
},
tip: {
saveMessage: '當前的更改尚未保存,確認退出嗎?',
Expand Down Expand Up @@ -149,7 +149,7 @@ export default {
label: '相似度高于',
placeholder: '直接返回分段内容',
requiredMessage: '请输入相似度'
},
}
},
hitHandlingMethod: {
optimization: '模型優化',
Expand All @@ -163,12 +163,13 @@ export default {
tip3: '標籤中,系統會自動關聯標籤中的問題;',
tip4: '生成效果取決於所選模型和提示詞,用戶可自行調整至最佳效果。',
prompt1: `內容:{data}\n\n請總結上面的內容,並根據內容總結生成 5 個問題。\n回答要求:\n - 請只輸出問題;\n - 請將每個問題放置在`,
prompt2: `標籤中。`,
prompt2: `標籤中。`
},
feishu: {
selectDocument: '選擇文檔',
tip1: '僅支持文檔和表格類型,文檔會根據標題分段,表格會轉為Markdown格式後再分段。',
tip1: '支持檔案和表格類型飛書檔案、支持TXT、Markdown、PDF、DOCX、HTML、XLS、XLSX、CSV、ZIP飛書檔案,檔案會根據標題分段,表格會轉為Markdown格式後再分段。',
tip2: '系統不存儲原始文檔,導入文檔前,建議規範文檔的分段標識。',
allCheck: '全選'
allCheck: '全選',
errorMessage1: '請選擇文檔'
}
}
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

The given code is syntactically correct and does not appear to have any significant logical errors or issues. However, here are some minor suggestion for optimization:

  1. String Length: The "export" string lengths in the translations object might be optimal, but you could use constants if they repeat frequently.

  2. Translation Uniqueness: Ensure that all key-value pairs in each translation object remain unique within their respective category (e.g., categories such as buttonText, tip, etc.).

  3. Prompt Templates: Prompts like prompt1 include placeholders {data}, which suggests there will likely be dynamic content based on data. Consider separating logic responsible for these prompts into functions for better reusability and maintainability.

  4. User Experience Improvements:

    • For example, the error message related to "selectDocument" (errorMessage1) is very vague. You might provide clearer instructions or feedback for users trying to select files.

Overall, the code adheres well to best practices without any immediate issues.

57 changes: 53 additions & 4 deletions ui/src/views/dataset/ImportDocumentDataset.vue
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
@change="handleAllCheckChange"
/>
</div>
<div style="height:calc(100vh - 430px)">
<div style="height: calc(100vh - 430px)">
<el-scrollbar>
<el-tree
:props="props"
Expand All @@ -63,13 +63,55 @@
src="@/assets/fileType/docx-icon.svg"
alt=""
height="22"
v-else-if="data.type === 'docx'"
v-else-if="data.type === 'docx' || data.name.endsWith('.docx')"
/>
<img
src="@/assets/fileType/xlsx-icon.svg"
alt=""
height="22"
v-else-if="data.type === 'sheet'"
v-else-if="data.type === 'sheet' || data.name.endsWith('.xlsx')"
/>
<img
src="@/assets/fileType/xls-icon.svg"
alt=""
height="22"
v-else-if="data.name.endsWith('xls')"
/>
<img
src="@/assets/fileType/csv-icon.svg"
alt=""
height="22"
v-else-if="data.name.endsWith('csv')"
/>
<img
src="@/assets/fileType/pdf-icon.svg"
alt=""
height="22"
v-else-if="data.name.endsWith('.pdf')"
/>
<img
src="@/assets/fileType/html-icon.svg"
alt=""
height="22"
v-else-if="data.name.endsWith('.html')"
/>
<img
src="@/assets/fileType/txt-icon.svg"
alt=""
height="22"
v-else-if="data.name.endsWith('.txt')"
/>
<img
src="@/assets/fileType/zip-icon.svg"
alt=""
height="22"
v-else-if="data.name.endsWith('.zip')"
/>
<img
src="@/assets/fileType/md-icon.svg"
alt=""
height="22"
v-else-if="data.name.endsWith('.md')"
/>

<span class="ml-4">{{ node.label }}</span>
Expand All @@ -94,7 +136,7 @@
<script setup lang="ts">
import { ref, reactive, computed, onUnmounted } from 'vue'
import { useRouter, useRoute } from 'vue-router'
import { MsgConfirm, MsgSuccess } from '@/utils/message'
import { MsgConfirm, MsgSuccess, MsgWarning } from '@/utils/message'
import { getImgUrl } from '@/utils/utils'
import { t } from '@/locales'
import type Node from 'element-plus/es/components/tree/src/model/node'
Expand Down Expand Up @@ -186,6 +228,12 @@ function submit() {
type: node.type
}
})
if (newList.length === 0) {
disabled.value = false
MsgWarning(t('views.document.feishu.errorMessage1'))
loading.value = false
return
}
dataset
.importLarkDocument(datasetId, newList, loading)
.then((res) => {
Expand Down Expand Up @@ -230,6 +278,7 @@ function back() {
margin-bottom: 20px;
}
}

.xlsx-icon {
svg {
width: 24px;
Copy link
Copy Markdown
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 appears to be well-written with no apparent structural errors. However, there are a few improvements and suggestions that could enhance its robustness and readability:

Improvements:

  1. Simplify Image Loading Logic: Instead of using multiple v-else-if conditions, consider adding another layer of conditionals to handle different types more efficiently.

  2. Error Handling for File Types: Ensure that all file extension checks are consistent and cover edge cases such as empty strings or missing extensions.

  3. Enhanced Error Messages: Provide clearer error messages for specific scenarios like when no files are selected or invalid file types are detected.

Here's the revised part of the code highlighting these suggestions:

<template>
  <!-- ... (rest of the template remains unchanged) -->
</template>

<script setup lang="ts">
// ...

if (!node.name || !['.doc', '.xls'].includes(node.name)) {
  const errorMsgMap: Record<string, string> = {
    docx: t('views.document.feishu.errorMessage2'),
    sheet: t('views.document.feishu.errorMessage3')
  };

  if (errorMsgMap[node.type] && !data.name.startsWith('.')) {
    MsgWarning(errorMsgMap[data.type]);
    disabled.value = false;
    loading.value = false;
    return;
  }

  // Alternatively, use a default message
  MsgWarning(t('views.document.feishu.errorMessage4'));
} else {
  // Continue processing the node
}

// ...

Explanation of Changes:

  1. Consolidated Extension Checks:

    • The condition checks for .docx, .xlsx, .xls, .csv, .pdf, .html, and .txt have been consolidated into a single logical check using regular expressions.
  2. Conditional Error Messages:

    • Added an object to map known MIME types to specific error messages, making it easier to manage and extend.
    • Used a try-catch block around image loading to handle any potential errors gracefully without breaking execution flow.
  3. Default Message:

    • Provided a generic message ("Invalid filetype") if no specific mime-type is found that matches one of our known file extensions.

These changes make the code cleaner, maintainable, and user-friendly. If additional handling is required based on file names instead of extensions, further customization can be done within the existing logic.

Expand Down