1
1
package dev .langchain4j .azure .openai .spring ;
2
2
3
3
import dev .langchain4j .data .message .AiMessage ;
4
- import dev .langchain4j .model .StreamingResponseHandler ;
5
4
import dev .langchain4j .model .azure .AzureOpenAiChatModel ;
6
5
import dev .langchain4j .model .azure .AzureOpenAiEmbeddingModel ;
7
6
import dev .langchain4j .model .azure .AzureOpenAiImageModel ;
15
14
import dev .langchain4j .model .chat .request .json .JsonObjectSchema ;
16
15
import dev .langchain4j .model .chat .request .json .JsonSchema ;
17
16
import dev .langchain4j .model .chat .request .json .JsonStringSchema ;
17
+ import dev .langchain4j .model .chat .response .ChatResponse ;
18
+ import dev .langchain4j .model .chat .response .StreamingChatResponseHandler ;
18
19
import dev .langchain4j .model .embedding .EmbeddingModel ;
19
20
import dev .langchain4j .model .image .ImageModel ;
20
- import dev .langchain4j .model .output .Response ;
21
21
import org .junit .jupiter .api .Test ;
22
22
import org .junit .jupiter .api .condition .EnabledIfEnvironmentVariable ;
23
23
import org .junit .jupiter .params .ParameterizedTest ;
@@ -67,7 +67,7 @@ void should_provide_chat_model(String deploymentName) {
67
67
68
68
ChatLanguageModel chatLanguageModel = context .getBean (ChatLanguageModel .class );
69
69
assertThat (chatLanguageModel ).isInstanceOf (AzureOpenAiChatModel .class );
70
- assertThat (chatLanguageModel .generate ("What is the capital of Germany?" )).contains ("Berlin" );
70
+ assertThat (chatLanguageModel .chat ("What is the capital of Germany?" )).contains ("Berlin" );
71
71
assertThat (context .getBean (AzureOpenAiChatModel .class )).isSameAs (chatLanguageModel );
72
72
});
73
73
}
@@ -87,7 +87,7 @@ void should_provide_chat_model_with_listeners() {
87
87
88
88
ChatLanguageModel chatLanguageModel = context .getBean (ChatLanguageModel .class );
89
89
assertThat (chatLanguageModel ).isInstanceOf (AzureOpenAiChatModel .class );
90
- assertThat (chatLanguageModel .generate ("What is the capital of Germany?" )).contains ("Berlin" );
90
+ assertThat (chatLanguageModel .chat ("What is the capital of Germany?" )).contains ("Berlin" );
91
91
assertThat (context .getBean (AzureOpenAiChatModel .class )).isSameAs (chatLanguageModel );
92
92
93
93
ChatModelListener listener1 = context .getBean ("listener1" , ChatModelListener .class );
@@ -159,7 +159,7 @@ void should_provide_chat_model_no_azure(String deploymentName) {
159
159
160
160
ChatLanguageModel chatLanguageModel = context .getBean (ChatLanguageModel .class );
161
161
assertThat (chatLanguageModel ).isInstanceOf (AzureOpenAiChatModel .class );
162
- assertThat (chatLanguageModel .generate ("What is the capital of Germany?" )).contains ("Berlin" );
162
+ assertThat (chatLanguageModel .chat ("What is the capital of Germany?" )).contains ("Berlin" );
163
163
164
164
assertThat (context .getBean (AzureOpenAiChatModel .class )).isSameAs (chatLanguageModel );
165
165
});
@@ -184,24 +184,24 @@ void should_provide_streaming_chat_model(String deploymentName) {
184
184
185
185
StreamingChatLanguageModel streamingChatLanguageModel = context .getBean (StreamingChatLanguageModel .class );
186
186
assertThat (streamingChatLanguageModel ).isInstanceOf (AzureOpenAiStreamingChatModel .class );
187
- CompletableFuture <Response < AiMessage > > future = new CompletableFuture <>();
188
- streamingChatLanguageModel .generate ("What is the capital of Germany?" , new StreamingResponseHandler < AiMessage > () {
187
+ CompletableFuture <ChatResponse > future = new CompletableFuture <>();
188
+ streamingChatLanguageModel .chat ("What is the capital of Germany?" , new StreamingChatResponseHandler () {
189
189
190
190
@ Override
191
- public void onNext (String token ) {
191
+ public void onPartialResponse (String partialResponse ) {
192
192
}
193
193
194
194
@ Override
195
- public void onComplete ( Response < AiMessage > response ) {
196
- future .complete (response );
195
+ public void onCompleteResponse ( ChatResponse completeResponse ) {
196
+ future .complete (completeResponse );
197
197
}
198
198
199
199
@ Override
200
200
public void onError (Throwable error ) {
201
201
}
202
202
});
203
- Response < AiMessage > response = future .get (60 , SECONDS );
204
- assertThat (response .content ().text ()).contains ("Berlin" );
203
+ ChatResponse response = future .get (60 , SECONDS );
204
+ assertThat (response .aiMessage ().text ()).contains ("Berlin" );
205
205
206
206
assertThat (context .getBean (AzureOpenAiStreamingChatModel .class )).isSameAs (streamingChatLanguageModel );
207
207
});
@@ -223,24 +223,24 @@ void should_provide_streaming_chat_model_with_listeners() {
223
223
224
224
StreamingChatLanguageModel streamingChatLanguageModel = context .getBean (StreamingChatLanguageModel .class );
225
225
assertThat (streamingChatLanguageModel ).isInstanceOf (AzureOpenAiStreamingChatModel .class );
226
- CompletableFuture <Response < AiMessage > > future = new CompletableFuture <>();
227
- streamingChatLanguageModel .generate ("What is the capital of Germany?" , new StreamingResponseHandler < AiMessage > () {
226
+ CompletableFuture <ChatResponse > future = new CompletableFuture <>();
227
+ streamingChatLanguageModel .chat ("What is the capital of Germany?" , new StreamingChatResponseHandler () {
228
228
229
229
@ Override
230
- public void onNext (String token ) {
230
+ public void onPartialResponse (String partialResponse ) {
231
231
}
232
232
233
233
@ Override
234
- public void onComplete ( Response < AiMessage > response ) {
235
- future .complete (response );
234
+ public void onCompleteResponse ( ChatResponse completeResponse ) {
235
+ future .complete (completeResponse );
236
236
}
237
237
238
238
@ Override
239
239
public void onError (Throwable error ) {
240
240
}
241
241
});
242
- Response < AiMessage > response = future .get (60 , SECONDS );
243
- assertThat (response .content ().text ()).contains ("Berlin" );
242
+ ChatResponse response = future .get (60 , SECONDS );
243
+ assertThat (response .aiMessage ().text ()).contains ("Berlin" );
244
244
245
245
assertThat (context .getBean (AzureOpenAiStreamingChatModel .class )).isSameAs (streamingChatLanguageModel );
246
246
0 commit comments