refacotr code
This commit is contained in:
parent
e11157ec41
commit
095efe428a
|
|
@ -10,7 +10,7 @@ import lombok.experimental.Accessors;
|
||||||
@TableName(value = "ai_question_record")
|
@TableName(value = "ai_question_record")
|
||||||
@Data
|
@Data
|
||||||
@Accessors(chain = true)
|
@Accessors(chain = true)
|
||||||
public class AiQuestionRecord extends BaseModel{
|
public class AiQuestionRecord extends BaseModel {
|
||||||
|
|
||||||
private String id;
|
private String id;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -26,6 +26,7 @@ import org.springframework.ai.chat.client.ChatClient;
|
||||||
import org.springframework.ai.chat.client.advisor.MessageChatMemoryAdvisor;
|
import org.springframework.ai.chat.client.advisor.MessageChatMemoryAdvisor;
|
||||||
import org.springframework.ai.chat.client.advisor.QuestionAnswerAdvisor;
|
import org.springframework.ai.chat.client.advisor.QuestionAnswerAdvisor;
|
||||||
import org.springframework.ai.chat.messages.UserMessage;
|
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.chat.prompt.Prompt;
|
||||||
import org.springframework.ai.document.Document;
|
import org.springframework.ai.document.Document;
|
||||||
import org.springframework.ai.document.DocumentReader;
|
import org.springframework.ai.document.DocumentReader;
|
||||||
|
|
@ -35,7 +36,6 @@ import org.springframework.ai.reader.TextReader;
|
||||||
import org.springframework.ai.reader.pdf.PagePdfDocumentReader;
|
import org.springframework.ai.reader.pdf.PagePdfDocumentReader;
|
||||||
import org.springframework.ai.transformer.splitter.TokenTextSplitter;
|
import org.springframework.ai.transformer.splitter.TokenTextSplitter;
|
||||||
import org.springframework.ai.vectorstore.VectorStore;
|
import org.springframework.ai.vectorstore.VectorStore;
|
||||||
import org.springframework.ai.chat.model.ChatResponse;
|
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
import org.springframework.transaction.annotation.Transactional;
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
import org.springframework.web.multipart.MultipartFile;
|
import org.springframework.web.multipart.MultipartFile;
|
||||||
|
|
@ -52,32 +52,25 @@ import java.util.stream.Collectors;
|
||||||
@Service
|
@Service
|
||||||
public class ChatService {
|
public class ChatService {
|
||||||
|
|
||||||
|
private static final List<String> ALLOWS_FILE_TYPES = List.of("doc", "docx", "txt", "csv", "xls", "xlsx", "pdf", "ppt", "pptx");
|
||||||
@Resource
|
@Resource
|
||||||
private VectorStore vectorStore;
|
private VectorStore vectorStore;
|
||||||
|
|
||||||
@Resource
|
@Resource
|
||||||
private OllamaChatModel model;
|
private OllamaChatModel model;
|
||||||
|
|
||||||
@Resource
|
@Resource
|
||||||
private MessageChatMemoryAdvisor messageChatMemoryAdvisor;
|
private MessageChatMemoryAdvisor messageChatMemoryAdvisor;
|
||||||
|
|
||||||
@Resource
|
@Resource
|
||||||
private QuestionAnswerAdvisor questionAnswerAdvisor;
|
private QuestionAnswerAdvisor questionAnswerAdvisor;
|
||||||
|
|
||||||
@Resource
|
@Resource
|
||||||
private AiFileUploadRecordMapper aiFileUploadRecordMapper;
|
private AiFileUploadRecordMapper aiFileUploadRecordMapper;
|
||||||
|
|
||||||
@Resource
|
@Resource
|
||||||
private AiQuestionRecordMapper aiQuestionRecordMapper;
|
private AiQuestionRecordMapper aiQuestionRecordMapper;
|
||||||
|
|
||||||
@Resource
|
@Resource
|
||||||
private ElePropertyConfig elePropertyConfig;
|
private ElePropertyConfig elePropertyConfig;
|
||||||
|
|
||||||
private static final List<String> ALLOWS_FILE_TYPES = List.of("doc", "docx", "txt", "csv", "xls", "xlsx", "pdf", "ppt", "pptx");
|
|
||||||
|
|
||||||
public ElectromagneticResult<?> deleteDocument(List<String> ids) {
|
public ElectromagneticResult<?> deleteDocument(List<String> ids) {
|
||||||
List<String> vectorIds = aiFileUploadRecordMapper.selectList(Wrappers.lambdaQuery(AiFileUploadRecord.class)
|
List<String> vectorIds = aiFileUploadRecordMapper.selectList(Wrappers.lambdaQuery(AiFileUploadRecord.class)
|
||||||
.in(AiFileUploadRecord::getId, ids))
|
.in(AiFileUploadRecord::getId, ids))
|
||||||
.stream()
|
.stream()
|
||||||
.map(AiFileUploadRecord::getVectorId)
|
.map(AiFileUploadRecord::getVectorId)
|
||||||
.collect(Collectors.toList());
|
.collect(Collectors.toList());
|
||||||
|
|
|
||||||
|
|
@ -15,7 +15,6 @@ import com.electromagnetic.industry.software.manage.service.FileFormatService;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.stream.Collectors;
|
|
||||||
|
|
||||||
@Service
|
@Service
|
||||||
public class FileFormatServiceImpl extends ServiceImpl<FileFormatMapper, FileFormat> implements FileFormatService {
|
public class FileFormatServiceImpl extends ServiceImpl<FileFormatMapper, FileFormat> implements FileFormatService {
|
||||||
|
|
|
||||||
|
|
@ -10,7 +10,6 @@ spring.datasource.username=em_user_dev
|
||||||
spring.datasource.password=Szsd#2O25$dev
|
spring.datasource.password=Szsd#2O25$dev
|
||||||
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
|
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
|
||||||
spring.datasource.type=com.alibaba.druid.pool.DruidDataSource
|
spring.datasource.type=com.alibaba.druid.pool.DruidDataSource
|
||||||
|
|
||||||
# es
|
# es
|
||||||
spring.elasticsearch.password=123456
|
spring.elasticsearch.password=123456
|
||||||
spring.elasticsearch.username=elastic
|
spring.elasticsearch.username=elastic
|
||||||
|
|
|
||||||
|
|
@ -29,10 +29,10 @@
|
||||||
// documents = documents.subList(0, 200);
|
// documents = documents.subList(0, 200);
|
||||||
// vectorStore.write(documents);
|
// vectorStore.write(documents);
|
||||||
//
|
//
|
||||||
//// Path tempFile = Paths.get(file.getAbsolutePath());
|
/// / Path tempFile = Paths.get(file.getAbsolutePath());
|
||||||
//// DocumentReader documentReader = new TextReader(String.valueOf(tempFile.toUri().toURL()));
|
/// / DocumentReader documentReader = new TextReader(String.valueOf(tempFile.toUri().toURL()));
|
||||||
//// List<Document> documents = documentReader.get();
|
/// / List<Document> documents = documentReader.get();
|
||||||
//// vectorStore.write(documents);
|
/// / vectorStore.write(documents);
|
||||||
// }
|
// }
|
||||||
//
|
//
|
||||||
//}
|
//}
|
||||||
|
|
|
||||||
|
|
@ -9,11 +9,11 @@ import lombok.NoArgsConstructor;
|
||||||
@AllArgsConstructor
|
@AllArgsConstructor
|
||||||
public class PageFile {
|
public class PageFile {
|
||||||
|
|
||||||
private int pageNumber;
|
private int pageNumber;
|
||||||
|
|
||||||
private String content;
|
private String content;
|
||||||
|
|
||||||
private String fileName;
|
private String fileName;
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue