feat: rag的api
This commit is contained in:
@@ -21,6 +21,7 @@ import org.springframework.ai.vectorstore.SearchRequest;
|
||||
import org.springframework.ai.vectorstore.SimpleVectorStore;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
import reactor.core.publisher.Flux;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
@@ -61,7 +62,7 @@ public class RAGApiTest {
|
||||
@Test
|
||||
public void chat() {
|
||||
// 构建提问
|
||||
String message = "李永德,哪年出生的";
|
||||
String message = "拆装出库的操作流程是什么?";
|
||||
|
||||
// 构建推理模板
|
||||
String SYSTEM_PROMPT = """
|
||||
@@ -72,7 +73,7 @@ public class RAGApiTest {
|
||||
{documents}
|
||||
""";
|
||||
// 读取向量库信息
|
||||
SearchRequest request = SearchRequest.query(message).withTopK(5).withFilterExpression("knowledge == '德德'");
|
||||
SearchRequest request = SearchRequest.query(message).withTopK(5).withFilterExpression("knowledge == '富士迈泰国项目软件方案'");
|
||||
// 相似性搜索
|
||||
List<Document> documents = pgVectorStore.similaritySearch(request);
|
||||
String documentsCollectors = documents.stream().map(Document::getContent).collect(Collectors.joining());
|
||||
@@ -84,7 +85,8 @@ public class RAGApiTest {
|
||||
messages.add(ragMessage);
|
||||
|
||||
// 提问
|
||||
ChatResponse chatResponse = ollamaChatClient.call(new Prompt(messages, OllamaOptions.create().withModel("deepseek-r1:7b")));
|
||||
log.info("测试结果:{}", JSON.toJSONString(chatResponse));
|
||||
// ChatResponse chatResponse = ollamaChatClient.call(new Prompt(messages, OllamaOptions.create().withModel("deepseek-r1:7b")));
|
||||
Flux<ChatResponse> stream = ollamaChatClient.stream(new Prompt(messages, OllamaOptions.create().withModel("deepseek-r1:7b")));
|
||||
log.info("测试结果:{}", JSON.toJSONString(stream));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user