将AI中支持上传的文件类型转移到配置文件

This commit is contained in:
chenxudong 2025-04-22 10:02:19 +08:00
parent 832ed737bf
commit 881e5bf5c9
3 changed files with 11 additions and 2 deletions

View File

@ -6,6 +6,8 @@ import lombok.Getter;
import org.springframework.beans.factory.annotation.Value; import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import java.util.List;
@Component @Component
public class ElePropertyConfig { public class ElePropertyConfig {
@ -73,6 +75,13 @@ public class ElePropertyConfig {
@Value("${prjRootPath}") @Value("${prjRootPath}")
private String prjRootPath; private String prjRootPath;
@Value("${allow.upload.file.types}")
private String allowUploadFileTypes;
public List<String> getAiAllowUploadFileTypes() {
return List.of(allowUploadFileTypes.split(","));
}
public String getEleTmpPath() { public String getEleTmpPath() {
if (EleCommonUtil.isWinOs()) { if (EleCommonUtil.isWinOs()) {
return winPrefix + prjRootPath + eleTmpPath; return winPrefix + prjRootPath + eleTmpPath;

View File

@ -49,7 +49,6 @@ import java.util.*;
@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
@ -90,7 +89,7 @@ public class ChatService {
} }
String fileType = FileUtil.extName(file.getOriginalFilename()); String fileType = FileUtil.extName(file.getOriginalFilename());
if (!ALLOWS_FILE_TYPES.contains(fileType)) { if (!elePropertyConfig.getAiAllowUploadFileTypes().contains(fileType)) {
return ElectromagneticResultUtil.fail("-1", StrFormatter.format("当前格式 {} 不支持", fileType)); return ElectromagneticResultUtil.fail("-1", StrFormatter.format("当前格式 {} 不支持", fileType));
} }

View File

@ -24,6 +24,7 @@ spring.ai.vectorstore.elasticsearch.initialize-schema=true
spring.ai.vectorstore.elasticsearch.index-name=rag spring.ai.vectorstore.elasticsearch.index-name=rag
spring.ai.vectorstore.elasticsearch.dimensions=768 spring.ai.vectorstore.elasticsearch.dimensions=768
spring.ai.vectorstore.elasticsearch.similarity=cosine spring.ai.vectorstore.elasticsearch.similarity=cosine
allow.upload.file.types=doc, docx, txt, csv, xls, xlsx, pdf, ppt", pptx
# mybatis # mybatis
mybatis-plus.mapper-locations=classpath:sqlmapper/*.xml mybatis-plus.mapper-locations=classpath:sqlmapper/*.xml
mybatis-plus.configuration.log-impl=org.apache.ibatis.logging.stdout.StdOutImpl mybatis-plus.configuration.log-impl=org.apache.ibatis.logging.stdout.StdOutImpl