|
@@ -22,6 +22,7 @@ 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.embedding.EmbeddingModel;
|
|
|
import org.springframework.ai.ollama.OllamaChatModel;
|
|
|
import org.springframework.ai.vectorstore.SearchRequest;
|
|
|
import org.springframework.ai.vectorstore.VectorStore;
|
|
@@ -46,12 +47,14 @@ import java.util.stream.Collectors;
|
|
|
public class ChatService {
|
|
|
|
|
|
private static final MD5 MD5 = cn.hutool.crypto.digest.MD5.create();
|
|
|
- private static final String PATH = Objects.requireNonNull(ChatService.class.getClassLoader().getResource("")).getPath() + "\\ai_doc\\";
|
|
|
+ private static final String PATH = System.getProperty("user.dir") + "/ai_doc/";
|
|
|
private static final List<Message> LIST_MESSAGE = new ArrayList<>();
|
|
|
|
|
|
@Resource
|
|
|
private VectorStore vectorStore;
|
|
|
@Resource
|
|
|
+ private EmbeddingModel embeddingModel;
|
|
|
+ @Resource
|
|
|
private OllamaChatModel ollamaChatModel;
|
|
|
@Resource
|
|
|
private ChatHistoryService chatHistoryService;
|
|
@@ -117,12 +120,12 @@ public class ChatService {
|
|
|
* @return 内容总结
|
|
|
*/
|
|
|
public Flux<String> chatSummaryStream(String message, MultipartFile file) throws CustomException {
|
|
|
+ embeddingModel.embed("");
|
|
|
Tuple supportFile = isSupportFile(file);
|
|
|
String fileName = supportFile.get(1);
|
|
|
String fileTypeCn = supportFile.get(2);
|
|
|
DocumentReader reader = supportFile.get(3);
|
|
|
String context = fileTypeCn + " : " + fileName + " ====> " + mergeDocuments(reader.get()).replace("\n", " ");
|
|
|
- Log.info(this.getClass(), context);
|
|
|
return stream(message, new UserMessage(context + " : " + message));
|
|
|
}
|
|
|
|
|
@@ -146,7 +149,6 @@ public class ChatService {
|
|
|
* @return 提示词
|
|
|
*/
|
|
|
private Prompt getChatPrompt2String(String message, Message context) {
|
|
|
- Log.info(this.getClass(), "{} message : {}", "user", message);
|
|
|
ChatService.LIST_MESSAGE.add(new SystemMessage(userConfig.getSysMessage()));
|
|
|
if (context.getMessageType().equals(MessageType.SYSTEM)) {
|
|
|
ChatService.LIST_MESSAGE.add(new UserMessage(message));
|