File tree Expand file tree Collapse file tree
samples/spring-ai/assistant/src/main/java/com/example/assistant/service Expand file tree Collapse file tree Original file line number Diff line number Diff line change 11package com .example .assistant .service ;
22
3+ import org .springframework .ai .chat .client .ChatClient ;
4+ import org .springframework .ai .chat .memory .ChatMemory ;
35import org .springframework .ai .chat .memory .MessageWindowChatMemory ;
46import org .springframework .ai .chat .memory .repository .jdbc .JdbcChatMemoryRepository ;
57import org .springframework .ai .chat .memory .repository .jdbc .PostgresChatMemoryRepositoryDialect ;
@@ -51,9 +53,9 @@ public String getCurrentConversationId() {
5153 /**
5254 * Add the conversation ID parameter to the advisor
5355 */
54- public void addConversationIdToAdvisor (Object advisor ) {
56+ public void addConversationIdToAdvisor (ChatClient . AdvisorSpec advisor ) {
5557 String conversationId = getCurrentConversationId ();
56- advisor .getClass ().cast (advisor );
5758 logger .debug ("Adding conversation ID {} to advisor" , conversationId );
59+ advisor .param (ChatMemory .CONVERSATION_ID , conversationId );
5860 }
5961}
Original file line number Diff line number Diff line change @@ -63,7 +63,7 @@ public String processChat(ChatRequest request) {
6363 return RetryUtils .executeWithRetry (() -> {
6464 var chatResponse = chatClient
6565 .prompt ().user (request .prompt ())
66- .advisors (advisor -> advisor . param ( ChatMemory . CONVERSATION_ID , chatMemoryService . getCurrentConversationId ()) )
66+ .advisors (chatMemoryService :: addConversationIdToAdvisor )
6767 .call ().chatResponse ();
6868
6969 return (chatResponse != null ) ? chatResponse .getResult ().getOutput ().getText () : "I don't know - no response received." ;
You can’t perform that action at this time.
0 commit comments