Skip to content

Commit

Permalink
Use QuestionAnswerAdvisor
Browse files Browse the repository at this point in the history
  • Loading branch information
showpune committed Jun 17, 2024
1 parent 9a8fc5f commit 4c296c3
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 6 deletions.
Original file line number Diff line number Diff line change
@@ -1,19 +1,16 @@
package org.springframework.samples.petclinic.chat;

import org.springframework.ai.chat.client.ChatClient;
import org.springframework.ai.chat.messages.UserMessage;
import org.springframework.ai.chat.model.ChatModel;
import org.springframework.ai.chat.prompt.PromptTemplate;
import org.springframework.ai.chat.prompt.SystemPromptTemplate;
import org.springframework.ai.document.Document;
import org.springframework.ai.vectorstore.VectorStore;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.core.io.Resource;
import org.springframework.stereotype.Component;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.function.Consumer;

Expand All @@ -40,7 +37,7 @@ public class Agent {
public String chat(String userMessage, String username) {

try {
String processedMessage = chatModel.call(TRANSLATE+"\n"+userMessage);
String processedMessage = chatModel.call(TRANSLATE + "\n" + userMessage);

Consumer<ChatClient.AdvisorSpec> advisorSpecConsumer = advisorSpec -> {
advisorSpec.param(CHAT_MEMORY_CONVERSATION_ID_KEY, username);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,7 @@ public ChatClient chatClient(ChatClient.Builder chatClientBuilder) {
@Bean
public ChatClientCustomizer chatClientCustomizer(VectorStore vectorStore) {
ChatMemory chatMemory = new InMemoryChatMemory();
return b -> b.defaultAdvisors(new PromptChatMemoryAdvisor(chatMemory)
, new QuestionAnswerAdvisor(vectorStore, SearchRequest.defaults()));
return b -> b.defaultAdvisors(new PromptChatMemoryAdvisor(chatMemory), new QuestionAnswerAdvisor(vectorStore, SearchRequest.defaults()));
}

@Bean
Expand Down

0 comments on commit 4c296c3

Please sign in to comment.