RAG
This commit is contained in:
parent
6e91637ef2
commit
fada2aab78
10
pom.xml
10
pom.xml
@ -55,11 +55,11 @@
|
|||||||
<artifactId>langchain4j</artifactId>
|
<artifactId>langchain4j</artifactId>
|
||||||
<version>1.1.0</version>
|
<version>1.1.0</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
<!-- <dependency>-->
|
<dependency>
|
||||||
<!-- <groupId>dev.langchain4j</groupId>-->
|
<groupId>dev.langchain4j</groupId>
|
||||||
<!-- <artifactId>langchain4j-spring-boot-starter</artifactId>-->
|
<artifactId>langchain4j-spring-boot-starter</artifactId>
|
||||||
<!-- <version>1.1.0-beta7</version>-->
|
<version>1.1.0-beta7</version>
|
||||||
<!-- </dependency>-->
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
<build>
|
<build>
|
||||||
|
@ -40,22 +40,19 @@ public class RagConfig {
|
|||||||
|
|
||||||
EmbeddingStoreIngestor ingestor = EmbeddingStoreIngestor.builder()
|
EmbeddingStoreIngestor ingestor = EmbeddingStoreIngestor.builder()
|
||||||
.documentSplitter(documentByParagraphSplitter)
|
.documentSplitter(documentByParagraphSplitter)
|
||||||
.textSegmentTransformer(textSegment -> {
|
.textSegmentTransformer(textSegment -> TextSegment.from(
|
||||||
return TextSegment.from(
|
textSegment.metadata().getString("file_name") + "\n" + textSegment.text(),
|
||||||
textSegment.metadata().getString("file_name") + "\n" + textSegment.text(),
|
textSegment.metadata()
|
||||||
textSegment.metadata()
|
))
|
||||||
);
|
|
||||||
})
|
|
||||||
.embeddingModel(qwenEmbeddingModel)
|
.embeddingModel(qwenEmbeddingModel)
|
||||||
.embeddingStore(embeddingStore)
|
.embeddingStore(embeddingStore)
|
||||||
.build();
|
.build();
|
||||||
ingestor.ingest(documents);
|
ingestor.ingest(documents);
|
||||||
EmbeddingStoreContentRetriever contentRetriever = EmbeddingStoreContentRetriever.builder()
|
return EmbeddingStoreContentRetriever.builder()
|
||||||
.embeddingStore(embeddingStore)
|
.embeddingStore(embeddingStore)
|
||||||
.embeddingModel(qwenEmbeddingModel)
|
.embeddingModel(qwenEmbeddingModel)
|
||||||
.maxResults(5)
|
.maxResults(5)
|
||||||
.minScore(0.75)
|
.minScore(0.75)
|
||||||
.build();
|
.build();
|
||||||
return contentRetriever;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2,6 +2,7 @@ package com.huangge1199.ai.controller;
|
|||||||
|
|
||||||
import com.huangge1199.ai.common.R;
|
import com.huangge1199.ai.common.R;
|
||||||
import com.huangge1199.ai.service.LangChainService;
|
import com.huangge1199.ai.service.LangChainService;
|
||||||
|
import dev.langchain4j.service.Result;
|
||||||
import jakarta.annotation.Resource;
|
import jakarta.annotation.Resource;
|
||||||
import org.springframework.web.bind.annotation.PostMapping;
|
import org.springframework.web.bind.annotation.PostMapping;
|
||||||
import org.springframework.web.bind.annotation.RequestBody;
|
import org.springframework.web.bind.annotation.RequestBody;
|
||||||
@ -44,4 +45,16 @@ public class LangChainController {
|
|||||||
LangChainService.Report result = langChainService.chatForReport(message);
|
LangChainService.Report result = langChainService.chatForReport(message);
|
||||||
return R.ok(result);
|
return R.ok(result);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* RAG
|
||||||
|
*
|
||||||
|
* @param message 输入信息
|
||||||
|
* @return ai返回结果
|
||||||
|
*/
|
||||||
|
@PostMapping("/chatWithRag")
|
||||||
|
public R<Result<String>> chatWithRag(@RequestBody String message) {
|
||||||
|
Result<String> result = langChainService.chatWithRag(message);
|
||||||
|
return R.ok(result);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
package com.huangge1199.ai.service;
|
package com.huangge1199.ai.service;
|
||||||
|
|
||||||
|
import dev.langchain4j.service.Result;
|
||||||
import dev.langchain4j.service.SystemMessage;
|
import dev.langchain4j.service.SystemMessage;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@ -18,5 +19,9 @@ public interface LangChainService {
|
|||||||
@SystemMessage(fromResource = "system-prompt.txt")
|
@SystemMessage(fromResource = "system-prompt.txt")
|
||||||
Report chatForReport(String message);
|
Report chatForReport(String message);
|
||||||
|
|
||||||
record Report(String name, List<String> list){}
|
record Report(String name, List<String> list) {
|
||||||
|
}
|
||||||
|
|
||||||
|
@SystemMessage(fromResource = "system-prompt.txt")
|
||||||
|
Result<String> chatWithRag(String message);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user