Skip to content

Commit

Permalink
Update
Browse files Browse the repository at this point in the history
  • Loading branch information
ThomasVitale committed Nov 11, 2024
1 parent 7aba40c commit e3ff0dd
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ metadata:
backstage.io/techdocs-ref: dir:.
endoflife.date/products: spring-boot
github.com/project-slug: ${{ values.repoUrl.owner }}/${{ values.repoUrl.repo }}
github.com/workflows: commit-stage.yml
sonarqube.org/project-key: ${{ values.repoUrl.owner }}_${{ values.repoUrl.repo }}
spec:
type: service
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.ai.chat.client.ChatClient;
import org.springframework.ai.chat.client.advisor.QuestionAnswerAdvisor;
import org.springframework.ai.chat.client.advisor.RetrievalAugmentationAdvisor;
import org.springframework.ai.rag.retrieval.source.DocumentRetriever;
import org.springframework.ai.rag.retrieval.source.VectorStoreDocumentRetriever;
import org.springframework.ai.reader.TextReader;
import org.springframework.ai.transformer.splitter.TokenTextSplitter;
import org.springframework.ai.vectorstore.VectorStore;
Expand All @@ -16,16 +18,13 @@
import org.springframework.boot.context.event.ApplicationReadyEvent;
import org.springframework.context.ApplicationListener;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.io.Resource;
import org.springframework.jdbc.core.simple.JdbcClient;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import java.time.Duration;

@SpringBootApplication
public class Application {

Expand All @@ -46,18 +45,22 @@ class ChatController {
private static final Logger logger = LoggerFactory.getLogger(ChatController.class);

private final ChatClient chatClient;
private final VectorStore vectorStore;
private final DocumentRetriever documentRetriever;

ChatController(ChatClient.Builder chatClientBuilder, VectorStore vectorStore) {
this.chatClient = chatClientBuilder.build();
this.vectorStore = vectorStore;
this.documentRetriever = VectorStoreDocumentRetriever.builder()
.vectorStore(vectorStore)
.build();
}

@PostMapping("/chat")
String chatWithDocument(@RequestBody String message) {
logger.info("Received user message: {}", message);
return chatClient.prompt()
.advisors(new QuestionAnswerAdvisor(vectorStore))
.advisors(RetrievalAugmentationAdvisor.builder()
.documentRetriever(documentRetriever)
.build())
.user(message)
.call()
.content();
Expand Down

0 comments on commit e3ff0dd

Please sign in to comment.