fix(knowledge): 优化多文件上传体验
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
package com.lanyuanxiaoyao.service.ai.knowledge.service;
|
||||
|
||||
import cn.hutool.core.io.FileUtil;
|
||||
import cn.hutool.core.lang.Pair;
|
||||
import cn.hutool.core.util.IdUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.lanyuanxiaoyao.service.ai.knowledge.entity.EmbeddingContext;
|
||||
@@ -8,6 +9,7 @@ import com.lanyuanxiaoyao.service.ai.knowledge.entity.Knowledge;
|
||||
import com.lanyuanxiaoyao.service.ai.knowledge.entity.vo.DataFileVO;
|
||||
import com.yomahub.liteflow.core.FlowExecutor;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.Executors;
|
||||
import org.eclipse.collections.api.factory.Lists;
|
||||
@@ -79,9 +81,15 @@ public class EmbeddingService {
|
||||
public void submit(Long id, String mode, ImmutableList<String> ids) {
|
||||
executors.submit(() -> {
|
||||
Knowledge knowledge = knowledgeService.get(id);
|
||||
List<Pair<Long, DataFileVO>> vos = Lists.mutable.empty();
|
||||
for (String fileId : ids) {
|
||||
DataFileVO vo = dataFileService.downloadFile(Long.parseLong(fileId));
|
||||
Long groupId = groupService.add(id, vo.getFilename());
|
||||
vos.add(Pair.of(groupId, vo));
|
||||
}
|
||||
for (Pair<Long, DataFileVO> pair : vos) {
|
||||
Long groupId = pair.getKey();
|
||||
DataFileVO vo = pair.getValue();
|
||||
EmbeddingContext context = EmbeddingContext.builder()
|
||||
.vectorSourceId(knowledge.getVectorSourceId())
|
||||
.groupId(groupId)
|
||||
|
||||
@@ -50,6 +50,7 @@ const DataImport: React.FC = () => {
|
||||
{
|
||||
body: [
|
||||
{
|
||||
id: 'a5219cc7-72dd-4199-9eeb-61305fe41075',
|
||||
type: 'form',
|
||||
wrapWithPanel: false,
|
||||
actions: [],
|
||||
@@ -93,6 +94,7 @@ const DataImport: React.FC = () => {
|
||||
{
|
||||
visibleOn: 'type === \'text\'',
|
||||
type: 'editor',
|
||||
required: true,
|
||||
label: '数据内容',
|
||||
name: 'content',
|
||||
language: 'plaintext',
|
||||
@@ -104,6 +106,7 @@ const DataImport: React.FC = () => {
|
||||
{
|
||||
visibleOn: 'type === \'file\'',
|
||||
type: 'input-file',
|
||||
required: true,
|
||||
name: 'files',
|
||||
label: '数据文件',
|
||||
autoUpload: false,
|
||||
@@ -144,9 +147,14 @@ const DataImport: React.FC = () => {
|
||||
type: 'button-toolbar',
|
||||
buttons: [
|
||||
{
|
||||
type: 'action',
|
||||
type: 'reset',
|
||||
label: '重置'
|
||||
},
|
||||
{
|
||||
type: 'submit',
|
||||
label: '预览',
|
||||
actionType: 'ajax',
|
||||
level: 'secondary',
|
||||
api: {
|
||||
method: 'post',
|
||||
url: 'http://127.0.0.1:8080/knowledge/preview_text',
|
||||
|
||||
Reference in New Issue
Block a user