|
@@ -87,8 +87,7 @@ public class ChatService {
|
|
|
* @param file 保存的文件
|
|
|
* @return 保存状态
|
|
|
*/
|
|
|
- public String uploadDocument(
|
|
|
- final MultipartFile file) throws CustomException {
|
|
|
+ public String uploadDocument(MultipartFile file) throws CustomException {
|
|
|
Tuple supportFile = isSupportFile(file);
|
|
|
File saveFile = supportFile.get(0);
|
|
|
String fileName = supportFile.get(1);
|
|
@@ -114,7 +113,7 @@ public class ChatService {
|
|
|
* @param keyword 关键词
|
|
|
* @return 文本内容
|
|
|
*/
|
|
|
- public String search(final String keyword) {
|
|
|
+ public String search(String keyword) {
|
|
|
SearchRequest searchRequest = SearchRequest.query(keyword).withSimilarityThreshold(0.5);
|
|
|
List<Document> documents = vectorStore.similaritySearch(searchRequest);
|
|
|
return mergeDocuments(documents);
|
|
@@ -126,7 +125,7 @@ public class ChatService {
|
|
|
* @param message 输入内容
|
|
|
* @return 回答内容
|
|
|
*/
|
|
|
- public Flux<String> chatStream(final String message) {
|
|
|
+ public Flux<String> chatStream(String message) {
|
|
|
String context = search(message);
|
|
|
Prompt prompt = new Prompt(List.of(
|
|
|
new SystemMessage(userConfig.getSysMessage()),
|
|
@@ -167,8 +166,8 @@ public class ChatService {
|
|
|
* @param file 文件
|
|
|
* @return 内容总结
|
|
|
*/
|
|
|
- public Flux<String> chatSummaryStream(final String message,
|
|
|
- final MultipartFile file) {
|
|
|
+ public Flux<String> chatSummaryStream(String message,
|
|
|
+ MultipartFile file) {
|
|
|
embeddingModel.embed("");
|
|
|
Tuple supportFile;
|
|
|
try {
|
|
@@ -194,7 +193,7 @@ public class ChatService {
|
|
|
* @param documents 文档列表
|
|
|
* @return 合并后的文档
|
|
|
*/
|
|
|
- private String mergeDocuments(final List<Document> documents) {
|
|
|
+ private String mergeDocuments(List<Document> documents) {
|
|
|
return MergeDocuments.mergeDocuments(documents).stream()
|
|
|
.map(Document::getContent).collect(Collectors.joining("\n"));
|
|
|
}
|
|
@@ -203,12 +202,12 @@ public class ChatService {
|
|
|
/**
|
|
|
* chat stream 封装.
|
|
|
*
|
|
|
- * @param userMessage 提问内容
|
|
|
+ * @param userMessage 提问内容
|
|
|
* @param sysOrUserMessage 用户或系统提示词
|
|
|
* @return flux
|
|
|
*/
|
|
|
- private Flux<String> stream(final Message userMessage,
|
|
|
- final Message sysOrUserMessage) {
|
|
|
+ private Flux<String> stream(Message userMessage,
|
|
|
+ Message sysOrUserMessage) {
|
|
|
String userId = SaManager.getStpLogic("").getLoginIdAsString();
|
|
|
StringBuilder chatMessage = new StringBuilder();
|
|
|
return ollamaChatModel.stream(sysOrUserMessage, userMessage).map(response -> {
|
|
@@ -231,8 +230,7 @@ public class ChatService {
|
|
|
* @param file 文件流
|
|
|
* @return 元组
|
|
|
*/
|
|
|
- private Tuple isSupportFile(
|
|
|
- final MultipartFile file) throws CustomException {
|
|
|
+ private Tuple isSupportFile(MultipartFile file) throws CustomException {
|
|
|
byte[] bytes;
|
|
|
try {
|
|
|
bytes = file.getBytes();
|