Skip to content

Commit f1a950e

Browse files
committed
Use QuestionAnswerAdvisor
1 parent d4c0d70 commit f1a950e

File tree

4 files changed

+8
-63
lines changed

4 files changed

+8
-63
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,21 @@
11
package com.javaaidev.webpageqa.chat;
22

3+
import org.springframework.ai.chat.client.ChatClient;
34
import org.springframework.web.bind.annotation.PostMapping;
45
import org.springframework.web.bind.annotation.RequestBody;
56
import org.springframework.web.bind.annotation.RestController;
67

78
@RestController
89
public class ChatController {
910

10-
private final ChatService chatService;
11+
private final ChatClient chatClient;
1112

12-
public ChatController(ChatService chatService) {
13-
this.chatService = chatService;
13+
public ChatController(ChatClient chatClient) {
14+
this.chatClient = chatClient;
1415
}
1516

1617
@PostMapping("/chat")
1718
public ChatResponse chat(@RequestBody ChatRequest request) {
18-
return new ChatResponse(chatService.chat(request));
19+
return new ChatResponse(chatClient.prompt().user(request.input()).call().content());
1920
}
2021
}
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package com.javaaidev.webpageqa.chat;
22

33
import org.springframework.ai.chat.client.ChatClient;
4+
import org.springframework.ai.chat.client.advisor.QuestionAnswerAdvisor;
45
import org.springframework.ai.vectorstore.VectorStore;
56
import org.springframework.context.annotation.Bean;
67
import org.springframework.context.annotation.Configuration;
@@ -9,13 +10,8 @@
910
public class ChatModuleConfiguration {
1011

1112
@Bean
12-
public ChatClient chatClient(ChatClient.Builder builder) {
13-
return builder.build();
14-
}
15-
16-
@Bean
17-
public ChatService chatService(ChatClient chatClient,
13+
public ChatClient chatClient(ChatClient.Builder builder,
1814
VectorStore vectorStore) {
19-
return new ChatService(chatClient, vectorStore);
15+
return builder.defaultAdvisors(new QuestionAnswerAdvisor(vectorStore)).build();
2016
}
2117
}

Diff for: src/main/java/com/javaaidev/webpageqa/chat/ChatService.java

-47
This file was deleted.

Diff for: src/main/resources/prompts/rag.st

-5
This file was deleted.

0 commit comments

Comments
 (0)