2
2
3
3
import static org .springframework .ai .chat .client .advisor .AbstractChatMemoryAdvisor .DEFAULT_CHAT_MEMORY_CONVERSATION_ID ;
4
4
5
+ import org .slf4j .Logger ;
6
+ import org .slf4j .LoggerFactory ;
5
7
import org .springframework .ai .chat .client .ChatClient ;
6
8
import org .springframework .ai .chat .client .advisor .MessageChatMemoryAdvisor ;
7
9
import org .springframework .ai .chat .client .advisor .SimpleLoggerAdvisor ;
20
22
@ RequestMapping ("/" )
21
23
public class PetclinicChatClient {
22
24
25
+ private static final Logger LOG = LoggerFactory .getLogger (PetclinicChatClient .class );
26
+
23
27
// ChatModel is the primary interfaces for interacting with an LLM
24
28
// it is a request/response interface that implements the ModelModel
25
29
// interface. Make suer to visit the source code of the ChatModel and
26
- // checkout the interfaces in the core spring ai package.
30
+ // checkout the interfaces in the core Spring AI package.
27
31
private final ChatClient chatClient ;
28
32
29
33
public PetclinicChatClient (ChatClient .Builder builder , ChatMemory chatMemory ) {
30
34
// @formatter:off
31
35
this .chatClient = builder
32
36
.defaultSystem ("""
33
- You are a friendly AI assistant designed to help with the management of a veterinarian pet clinic called Spring Petclinic.
34
- Your job is to answer questions about and to perform actions on the user's behalf, mainly around
35
- veterinarians, owners, owners' pets and owners' visits.
36
- You are required to answer an a professional manner. If you don't know the answer, politely tell the user
37
- you don't know the answer, then ask the user a followup question to try and clarify the question they are asking.
38
- If you do know the answer, provide the answer but do not provide any additional followup questions.
39
- When dealing with vets, if the user is unsure about the returned results, explain that there may be additional data that was not returned.
40
- Only if the user is asking about the total number of all vets, answer that there are a lot and ask for some additional criteria.
41
- For owners, pets or visits - provide the correct data.
42
- """ )
37
+ You are a friendly AI assistant designed to help with the management of a veterinarian pet clinic called Spring Petclinic.
38
+ Your job is to answer questions about and to perform actions on the user's behalf, mainly around
39
+ veterinarians, owners, owners' pets and owners' visits.
40
+ You are required to answer an a professional manner. If you don't know the answer, politely tell the user
41
+ you don't know the answer, then ask the user a followup question to try and clarify the question they are asking.
42
+ If you do know the answer, provide the answer but do not provide any additional followup questions.
43
+ When dealing with vets, if the user is unsure about the returned results, explain that there may be additional data that was not returned.
44
+ Only if the user is asking about the total number of all vets, answer that there are a lot and ask for some additional criteria.
45
+ For owners, pets or visits - provide the correct data.
46
+ """ )
43
47
.defaultAdvisors (
44
48
// Chat memory helps us keep context when using the chatbot for up to 10 previous messages.
45
49
new MessageChatMemoryAdvisor (chatMemory , DEFAULT_CHAT_MEMORY_CONVERSATION_ID , 10 ), // CHAT MEMORY
@@ -64,7 +68,7 @@ public String exchange(@RequestBody String query) {
64
68
.call ()
65
69
.content ();
66
70
} catch (Exception exception ) {
67
- exception . printStackTrace ( );
71
+ LOG . error ( "Error processing chat message" , exception );
68
72
return "Chat is currently unavailable. Please try again later." ;
69
73
}
70
74
}
0 commit comments