优化代码。
This commit is contained in:
parent
1e374d22f0
commit
be0fb17009
|
|
@ -47,10 +47,6 @@
|
|||
<groupId>org.springframework.ai</groupId>
|
||||
<artifactId>spring-ai-starter-vector-store-mariadb</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.ai</groupId>
|
||||
<artifactId>spring-ai-pdf-document-reader</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.baomidou</groupId>
|
||||
<artifactId>mybatis-plus-spring-boot3-starter</artifactId>
|
||||
|
|
|
|||
|
|
@ -1,8 +1,8 @@
|
|||
package com.electromagnetic.industry.software.manage.service.serviceimpl;
|
||||
|
||||
import cn.hutool.core.io.FileUtil;
|
||||
import cn.hutool.core.io.IoUtil;
|
||||
import cn.hutool.core.text.StrFormatter;
|
||||
import cn.hutool.core.util.IdUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import cn.hutool.crypto.digest.DigestUtil;
|
||||
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
||||
|
|
@ -26,10 +26,8 @@ import org.springframework.ai.chat.messages.UserMessage;
|
|||
import org.springframework.ai.chat.model.ChatResponse;
|
||||
import org.springframework.ai.chat.prompt.Prompt;
|
||||
import org.springframework.ai.document.Document;
|
||||
import org.springframework.ai.document.DocumentReader;
|
||||
import org.springframework.ai.ollama.OllamaChatModel;
|
||||
import org.springframework.ai.ollama.api.OllamaOptions;
|
||||
import org.springframework.ai.reader.TextReader;
|
||||
import org.springframework.ai.transformer.splitter.TokenTextSplitter;
|
||||
import org.springframework.ai.vectorstore.SearchRequest;
|
||||
import org.springframework.ai.vectorstore.VectorStore;
|
||||
|
|
@ -40,8 +38,6 @@ import reactor.core.publisher.Flux;
|
|||
|
||||
import java.io.File;
|
||||
import java.nio.charset.Charset;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
import java.util.*;
|
||||
|
||||
@Slf4j
|
||||
|
|
@ -107,12 +103,8 @@ public class ChatService {
|
|||
List<Document> documents = new ArrayList<>();
|
||||
switch (Objects.requireNonNull(fileType)) {
|
||||
case "txt", "csv", "text" -> {
|
||||
String tmpPath = elePropertyConfig.getEleTmpPath() + File.separator + IdUtil.fastSimpleUUID() + "." + fileType;
|
||||
FileUtil.writeFromStream(file.getInputStream(), tmpPath);
|
||||
Path tempFile = Paths.get(tmpPath);
|
||||
DocumentReader documentReader = new TextReader(String.valueOf(tempFile.toUri().toURL()));
|
||||
documents = documentReader.get();
|
||||
FileUtil.del(tempFile);
|
||||
String content = IoUtil.read(file.getInputStream(), Charset.defaultCharset());
|
||||
documents.add(new Document(content));
|
||||
}
|
||||
case "xls", "xlsx" -> {
|
||||
String filePath = elePropertyConfig.getEleTmpPath() + File.separator + fileMd5 + "." + fileType;
|
||||
|
|
|
|||
Loading…
Reference in New Issue