14
14
* limitations under the License.
15
15
*/
16
16
17
- package org .springframework .ai .openai .chat .chatbot ;
17
+ package org .springframework .ai .openai .chat .service ;
18
18
19
19
import java .util .List ;
20
20
import java .util .Map ;
26
26
import org .junit .jupiter .api .condition .EnabledIfEnvironmentVariable ;
27
27
import org .slf4j .Logger ;
28
28
import org .slf4j .LoggerFactory ;
29
- import org .springframework .ai .chat .chatbot .ChatBot ;
29
+ import org .springframework .ai .chat .prompt .transformer .ChatServiceContext ;
30
+ import org .springframework .ai .chat .service .ChatService ;
31
+ import org .springframework .ai .chat .service .PromptTransformingChatService ;
30
32
import org .springframework .ai .openai .OpenAiChatOptions ;
31
33
import org .testcontainers .junit .jupiter .Container ;
32
34
import org .testcontainers .junit .jupiter .Testcontainers ;
33
35
import org .testcontainers .qdrant .QdrantContainer ;
34
36
35
- import org .springframework .ai .chat .chatbot .DefaultChatBot ;
36
- import org .springframework .ai .chat .history .ChatMemory ;
37
- import org .springframework .ai .chat .history .ChatMemoryChatBotListener ;
38
- import org .springframework .ai .chat .history .ChatMemoryRetriever ;
39
- import org .springframework .ai .chat .history .InMemoryChatMemory ;
40
- import org .springframework .ai .chat .history .LastMaxTokenSizeContentTransformer ;
41
- import org .springframework .ai .chat .history .SystemPromptChatMemoryAugmentor ;
42
- import org .springframework .ai .chat .history .VectorStoreChatMemoryChatBotListener ;
43
- import org .springframework .ai .chat .history .VectorStoreChatMemoryRetriever ;
37
+ import org .springframework .ai .chat .memory .ChatMemory ;
38
+ import org .springframework .ai .chat .memory .ChatMemoryChatServiceListener ;
39
+ import org .springframework .ai .chat .memory .ChatMemoryRetriever ;
40
+ import org .springframework .ai .chat .memory .InMemoryChatMemory ;
41
+ import org .springframework .ai .chat .memory .LastMaxTokenSizeContentTransformer ;
42
+ import org .springframework .ai .chat .memory .SystemPromptChatMemoryAugmentor ;
43
+ import org .springframework .ai .chat .memory .VectorStoreChatMemoryChatServiceListener ;
44
+ import org .springframework .ai .chat .memory .VectorStoreChatMemoryRetriever ;
44
45
import org .springframework .ai .chat .messages .UserMessage ;
45
46
import org .springframework .ai .chat .prompt .Prompt ;
46
- import org .springframework .ai .chat .prompt .transformer .PromptContext ;
47
47
import org .springframework .ai .chat .prompt .transformer .QuestionContextAugmentor ;
48
48
import org .springframework .ai .chat .prompt .transformer .TransformerContentType ;
49
49
import org .springframework .ai .chat .prompt .transformer .VectorStoreRetriever ;
@@ -89,7 +89,7 @@ public class LongShortTermChatMemoryWithRagIT {
89
89
static QdrantContainer qdrantContainer = new QdrantContainer ("qdrant/qdrant:v1.9.2" );
90
90
91
91
@ Autowired
92
- ChatBot chatBot ;
92
+ ChatService chatService ;
93
93
94
94
@ Autowired
95
95
RelevancyEvaluator relevancyEvaluator ;
@@ -122,29 +122,29 @@ public List<Document> apply(List<Document> documents) {
122
122
}
123
123
124
124
// @Autowired
125
- // StreamingChatBot streamingChatBot ;
125
+ // StreamingChatService streamingChatService ;
126
126
127
127
@ Test
128
- void memoryChatBot () {
128
+ void memoryChatService () {
129
129
130
130
loadData ();
131
131
132
132
var prompt = new Prompt (new UserMessage ("My name is Christian and I like mountain bikes." ));
133
- PromptContext promptContext = new PromptContext (prompt );
133
+ ChatServiceContext chatServiceContext = new ChatServiceContext (prompt );
134
134
135
- var chatBotResponse1 = this .chatBot .call (promptContext );
135
+ var chatServiceResponse1 = this .chatService .call (chatServiceContext );
136
136
137
- logger .info ("Response1: " + chatBotResponse1 .getChatResponse ().getResult ().getOutput ().getContent ());
137
+ logger .info ("Response1: " + chatServiceResponse1 .getChatResponse ().getResult ().getOutput ().getContent ());
138
138
139
- var chatBotResponse2 = this .chatBot .call (new PromptContext (
139
+ var chatServiceResponse2 = this .chatService .call (new ChatServiceContext (
140
140
new Prompt (new String ("What is my name and what bike model would you suggest for me?" ))));
141
- logger .info ("Response2: " + chatBotResponse2 .getChatResponse ().getResult ().getOutput ().getContent ());
141
+ logger .info ("Response2: " + chatServiceResponse2 .getChatResponse ().getResult ().getOutput ().getContent ());
142
142
143
- // logger.info(chatBotResponse2 .getPromptContext().getContents().toString());
144
- assertThat (chatBotResponse2 .getChatResponse ().getResult ().getOutput ().getContent ()).contains ("Christian" );
143
+ // logger.info(chatServiceResponse2 .getPromptContext().getContents().toString());
144
+ assertThat (chatServiceResponse2 .getChatResponse ().getResult ().getOutput ().getContent ()).contains ("Christian" );
145
145
146
146
EvaluationResponse evaluationResponse = this .relevancyEvaluator
147
- .evaluate (new EvaluationRequest (chatBotResponse2 ));
147
+ .evaluate (new EvaluationRequest (chatServiceResponse2 ));
148
148
149
149
assertTrue (evaluationResponse .isPass (), "Response is not relevant to the question" );
150
150
@@ -187,12 +187,15 @@ public TokenCountEstimator tokenCountEstimator() {
187
187
}
188
188
189
189
@ Bean
190
- public ChatBot memoryChatBot (OpenAiChatClient chatClient , VectorStore vectorStore ,
190
+ public ChatService memoryChatService (OpenAiChatClient chatClient , VectorStore vectorStore ,
191
191
TokenCountEstimator tokenCountEstimator , ChatMemory chatHistory ) {
192
192
193
- return DefaultChatBot .builder (chatClient )
193
+ return PromptTransformingChatService .builder (chatClient )
194
194
.withRetrievers (List .of (new VectorStoreRetriever (vectorStore , SearchRequest .defaults ()),
195
- new ChatMemoryRetriever (chatHistory , Map .of (TransformerContentType .SHORT_TERM_MEMORY , "" )),
195
+ ChatMemoryRetriever .builder ()
196
+ .withChatHistory (chatHistory )
197
+ .withMetadata (Map .of (TransformerContentType .SHORT_TERM_MEMORY , "" ))
198
+ .build (),
196
199
new VectorStoreChatMemoryRetriever (vectorStore , 10 ,
197
200
Map .of (TransformerContentType .LONG_TERM_MEMORY , "" ))))
198
201
@@ -214,19 +217,19 @@ public ChatBot memoryChatBot(OpenAiChatClient chatClient, VectorStore vectorStor
214
217
Set .of (TransformerContentType .LONG_TERM_MEMORY )),
215
218
new SystemPromptChatMemoryAugmentor (Set .of (TransformerContentType .SHORT_TERM_MEMORY ))))
216
219
217
- .withChatBotListeners (List .of (new ChatMemoryChatBotListener (chatHistory ),
218
- new VectorStoreChatMemoryChatBotListener (vectorStore ,
220
+ .withChatServiceListeners (List .of (new ChatMemoryChatServiceListener (chatHistory ),
221
+ new VectorStoreChatMemoryChatServiceListener (vectorStore ,
219
222
Map .of (TransformerContentType .LONG_TERM_MEMORY , "" ))))
220
223
.build ();
221
224
}
222
225
223
226
// @Bean
224
- // public StreamingChatBot memoryStreamingChatAgent(OpenAiChatClient
227
+ // public StreamingChatService memoryStreamingChatAgent(OpenAiChatClient
225
228
// streamingChatClient,
226
229
// VectorStore vectorStore, TokenCountEstimator tokenCountEstimator, ChatHistory
227
230
// chatHistory) {
228
231
229
- // return DefaultStreamingChatBot .builder(streamingChatClient)
232
+ // return StreamingPromptTransformingChatService .builder(streamingChatClient)
230
233
// .withRetrievers(List.of(new ChatHistoryRetriever(chatHistory), new
231
234
// DocumentChatHistoryRetriever(vectorStore, 10)))
232
235
// .withDocumentPostProcessors(List.of(new
0 commit comments