@@ -49,13 +74,17 @@ import { message } from 'ant-design-vue'
const text = ref('');
const state = reactive({
loading: true,
+ uploading: false,
+ useFile: false,
})
const params = reactive({
chunkSize: 500,
- chunkOverlap: 20
+ chunkOverlap: 20,
+ useParser: false,
})
const chunks = ref([]);
+const fileList = ref([]);
const wordCount = computed(() => text.value.split(/\s+/).filter(Boolean).length);
const charCount = computed(() => text.value.length)
@@ -78,19 +107,32 @@ const estimatedTokenCount = computed(() => {
})
const chunkText = async () => {
- if (text.value.length === 0) {
- message.error("请输入文本")
- return
+ let text_or_file = ''
+ if (state.useFile) {
+ if (fileList.value.length === 0) {
+ message.error("请上传文件")
+ return
+ }
+ console.log(fileList.value)
+ text_or_file = fileList.value.filter(file => file.status === 'done').map(file => file.response.file_path)[0]
+ } else {
+ if (text.value.length === 0) {
+ message.error("请输入文本")
+ return
+ }
+ text_or_file = text.value
}
+
try {
state.loading = true
const response = await fetch('/api/tools/text_chunking', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
- text: text.value,
+ text: text_or_file,
chunk_size: params.chunkSize,
- chunk_overlap: params.chunkOverlap
+ chunk_overlap: params.chunkOverlap,
+ use_parser: params.useParser
})
});
@@ -99,7 +141,7 @@ const chunkText = async () => {
}
const data = await response.json();
- chunks.value = data.nodes.map(node => node.text);
+ chunks.value = data.nodes;
state.loading = false
} catch (error) {
console.error('Error chunking text:', error);
@@ -141,6 +183,28 @@ const chunkText = async () => {
flex-direction: column;
margin-bottom: 15px;
+ .actions {
+ display: flex;
+ justify-content: space-between;
+ margin-bottom: 10px;
+ width: fit-content;
+ background-color: var(--gray-200);
+ padding: 8px 6px;
+ border-radius: 8px;
+
+ span {
+ color: var(--gray-900);
+ cursor: pointer;
+ padding: 4px 10px;
+ border-radius: 8px;
+ transition: background-color 0.3s;
+
+ &.active {
+ background-color: white;
+ }
+ }
+ }
+
textarea {
resize: vertical;
height: 300px;
@@ -149,7 +213,7 @@ const chunkText = async () => {
border-radius: 8px;
font-size: 1rem;
transition: border-color 0.3s;
- background-color: var(--gray-50);
+ background-color: var(--gray-100);
&:focus {
border-color: var(--main-color);
@@ -174,38 +238,36 @@ const chunkText = async () => {
}
.chunk {
- background-color: #f9fcff;
- border-radius: 4px;
- padding: 10px;
+ background-color: var(--main-5);
+ border: 1px solid var(--main-light-3);
+ border-radius: 8px;
+ padding: 16px;
margin-bottom: 10px;
- box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
+ box-shadow: 0 0 10px 2px rgba(0, 0, 0, 0.01);
break-inside: avoid; /* 避免元素被分割到不同列 */
+ // 强制换行
+ word-wrap: break-word;
+ word-break: break-all;
}
}
}
-@media (max-width: 768px) {
+@media (max-width: 980px) {
#result-cards {
column-count: 1;
}
}
-@media (min-width: 769px) and (max-width: 1200px) {
+@media (min-width: 981px) and (max-width: 1500px) {
#result-cards {
column-count: 2;
}
}
-@media (min-width: 1201px) and (max-width: 1900px) {
+@media (min-width: 1501px){
#result-cards {
column-count: 3;
}
}
-
-@media (min-width: 1901px){
- #result-cards {
- column-count: 4;
- }
-}
\ No newline at end of file
diff --git a/web/src/views/ToolsView.vue b/web/src/views/ToolsView.vue
index bdc33fa3..84a9569c 100644
--- a/web/src/views/ToolsView.vue
+++ b/web/src/views/ToolsView.vue
@@ -107,6 +107,7 @@ onMounted(() => {
p {
margin: 0;
+ color: var(--gray-800);
}
}
}