From 4c296c376612c25d558ea180bec82d3415723bcd Mon Sep 17 00:00:00 2001 From: showpune Date: Tue, 18 Jun 2024 00:37:15 +0800 Subject: [PATCH] Use QuestionAnswerAdvisor --- .../org/springframework/samples/petclinic/chat/Agent.java | 5 +---- .../springframework/samples/petclinic/chat/AgentConfig.java | 3 +-- 2 files changed, 2 insertions(+), 6 deletions(-) diff --git a/src/main/java/org/springframework/samples/petclinic/chat/Agent.java b/src/main/java/org/springframework/samples/petclinic/chat/Agent.java index c16c4de..219bffd 100644 --- a/src/main/java/org/springframework/samples/petclinic/chat/Agent.java +++ b/src/main/java/org/springframework/samples/petclinic/chat/Agent.java @@ -1,11 +1,9 @@ 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; @@ -13,7 +11,6 @@ import org.springframework.stereotype.Component; import java.util.HashMap; -import java.util.List; import java.util.Map; import java.util.function.Consumer; @@ -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 advisorSpecConsumer = advisorSpec -> { advisorSpec.param(CHAT_MEMORY_CONVERSATION_ID_KEY, username); diff --git a/src/main/java/org/springframework/samples/petclinic/chat/AgentConfig.java b/src/main/java/org/springframework/samples/petclinic/chat/AgentConfig.java index bb75f00..9fb5840 100644 --- a/src/main/java/org/springframework/samples/petclinic/chat/AgentConfig.java +++ b/src/main/java/org/springframework/samples/petclinic/chat/AgentConfig.java @@ -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