| | |
| | |
|
| | | import java.io.BufferedReader;
|
| | | import java.io.StringReader;
|
| | | import java.util.ArrayList;
|
| | | import java.util.Date;
|
| | | import java.util.HashMap;
|
| | | import java.util.List;
|
| | | import java.util.Map;
|
| | | import java.util.*;
|
| | |
|
| | | import org.springframework.web.bind.annotation.RequestParam;
|
| | | import org.springframework.web.multipart.MultipartFile;
|
| | |
| | |
|
| | | public ModelAndView addKnowledgeFile(SMTAIServerRequest tranReq, @RequestParam(value = "file", required = false) MultipartFile file) throws Exception
|
| | | {
|
| | | String fileName = file.getOriginalFilename();
|
| | | String groupId = tranReq.convParamToString("group_id", true);
|
| | | String fileText = SMTStatic.readTextStream(file.getInputStream());
|
| | | String fileText = "";
|
| | | String fileName = file.getOriginalFilename();
|
| | | String groupId = tranReq.convParamToString("group_id", true);
|
| | | fileText = SMTStatic.readTextStream(file.getInputStream());
|
| | |
|
| | | |
| | | String fileType;
|
| | | List<String> listBlock = null;
|
| | | if(fileName.endsWith(".md"))
|
| | | {
|
| | | fileType = "markdown";
|
| | | listBlock = splitMarkdownToVectorBlock(fileText);
|
| | | }
|
| | | else
|
| | | {
|
| | | return tranReq.returnJsonState(false, "文件格式不支持", null);
|
| | | }
|
| | | |
| | | String fileType = "";
|
| | | List<String> listBlock = null;
|
| | |
|
| | | // 先判断文件名是否为空,避免空指针异常
|
| | | if (fileName != null && fileName.contains(".")) {
|
| | | fileType = fileName.substring(fileName.lastIndexOf(".")).toLowerCase(); // 统一转换为小写,避免大小写问题
|
| | | }
|
| | |
|
| | | // 用 Set 存储支持的文件类型,提高可读性
|
| | | Set<String> supportedTypes = new HashSet<>(Arrays.asList(".md", ".pdf", ".docx", ".doc"));
|
| | | if (supportedTypes.contains(fileType)) {
|
| | | fileText = SMTAIServerApp.fileTranslTxt(file);
|
| | | } else {
|
| | | return tranReq.returnJsonState(false, "文件格式不支持", null);
|
| | | }
|
| | | listBlock = splitMarkdownToVectorBlock(fileText);
|
| | | List<String> listVector = new ArrayList<>();
|
| | | SMTLLMConnect llm = SMTAIServerApp.getApp().allocLLMConnect(null);
|
| | | try
|