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