|
@@ -2,15 +2,22 @@ package com.ruoyi.web.llm.controller;
|
2
|
2
|
|
3
|
3
|
import com.alibaba.fastjson2.JSONObject;
|
4
|
4
|
import com.ruoyi.common.core.controller.BaseController;
|
|
5
|
+import com.ruoyi.web.llm.service.ILangChainMilvusService;
|
|
6
|
+import dev.langchain4j.model.embedding.EmbeddingModel;
|
|
7
|
+import dev.langchain4j.model.embedding.onnx.bgesmallzhv15.BgeSmallZhV15EmbeddingModel;
|
|
8
|
+import io.milvus.client.MilvusServiceClient;
|
|
9
|
+import io.milvus.param.ConnectParam;
|
5
|
10
|
import org.noear.solon.ai.chat.ChatModel;
|
6
|
11
|
import org.noear.solon.ai.chat.ChatResponse;
|
7
|
12
|
import org.noear.solon.ai.chat.message.AssistantMessage;
|
8
|
13
|
import org.noear.solon.ai.chat.message.ChatMessage;
|
9
|
14
|
import org.noear.solon.ai.mcp.client.McpClientProvider;
|
|
15
|
+import org.springframework.beans.factory.annotation.Autowired;
|
10
|
16
|
import org.springframework.web.bind.annotation.GetMapping;
|
11
|
17
|
import org.springframework.web.bind.annotation.RequestMapping;
|
12
|
18
|
import org.springframework.web.bind.annotation.RestController;
|
13
|
19
|
import org.springframework.web.multipart.MultipartFile;
|
|
20
|
+import reactor.core.publisher.Flux;
|
14
|
21
|
|
15
|
22
|
import java.io.IOException;
|
16
|
23
|
import java.util.*;
|
|
@@ -26,6 +33,17 @@ import java.util.*;
|
26
|
33
|
@RequestMapping("/llm/mcp")
|
27
|
34
|
public class McpController extends BaseController
|
28
|
35
|
{
|
|
36
|
+ @Autowired
|
|
37
|
+ private ILangChainMilvusService langChainMilvusService;
|
|
38
|
+
|
|
39
|
+ private static final EmbeddingModel embeddingModel = new BgeSmallZhV15EmbeddingModel();
|
|
40
|
+
|
|
41
|
+ private static final MilvusServiceClient milvusClient = new MilvusServiceClient(
|
|
42
|
+ ConnectParam.newBuilder()
|
|
43
|
+ .withHost("192.168.28.188")
|
|
44
|
+ .withPort(19530)
|
|
45
|
+ .build());
|
|
46
|
+
|
29
|
47
|
/**
|
30
|
48
|
* 同步问答
|
31
|
49
|
* @return
|
|
@@ -54,6 +72,16 @@ public class McpController extends BaseController
|
54
|
72
|
return assistantMessage;
|
55
|
73
|
}
|
56
|
74
|
|
|
75
|
+ /**
|
|
76
|
+ * 调用LLM+RAG(外部文件)生成回答
|
|
77
|
+ */
|
|
78
|
+ @GetMapping("/answerWithDocument")
|
|
79
|
+ public Flux<AssistantMessage> answerWithDocumentAndCollection(String collectionName, String topicId, String chatId, String question) throws IOException
|
|
80
|
+ {
|
|
81
|
+ List<JSONObject> requests = langChainMilvusService.retrieveFromMilvus(milvusClient, embeddingModel, collectionName, question, 10);
|
|
82
|
+ return langChainMilvusService.generateAnswerWithDocumentAndCollection(embeddingModel, topicId, chatId, question, requests, "http://192.168.28.188:8000/v1/chat/completions");
|
|
83
|
+ }
|
|
84
|
+
|
57
|
85
|
|
58
|
86
|
/**
|
59
|
87
|
* 根据招标文件要求编写投标文件技术方案
|