@@ -97,26 +97,16 @@ public interface NoMemoryAiService {
9797 @ Test
9898 void extract_dialogue_test () throws Exception {
9999
100- LangChain4jWatsonxConfig .WatsonConfig watsonConfig = langchain4jWatsonConfig .defaultConfig ();
101- ChatModelConfig chatModelConfig = watsonConfig .chatModel ();
102- String modelId = langchain4jWatsonFixedRuntimeConfig .defaultConfig ().chatModel ().modelId ();
103100 String chatMemoryId = "userId" ;
104- String projectId = watsonConfig .projectId ();
105- Parameters parameters = Parameters .builder ()
106- .decodingMethod (chatModelConfig .decodingMethod ())
107- .temperature (chatModelConfig .temperature ())
108- .minNewTokens (chatModelConfig .minNewTokens ())
109- .maxNewTokens (chatModelConfig .maxNewTokens ())
110- .build ();
111101
112102 var input = """
113103 You are a helpful assistant
114104 Context:
115105
116106 Hello""" ;
117- var body = new TextGenerationRequest ( modelId , projectId , input , parameters );
107+
118108 mockServers .mockWatsonxBuilder (WireMockUtil .URL_WATSONX_CHAT_API , 200 )
119- .body (mapper .writeValueAsString (body ))
109+ .body (mapper .writeValueAsString (createRequest ( input ) ))
120110 .response ("""
121111 {
122112 "results": [
@@ -140,9 +130,9 @@ void extract_dialogue_test() throws Exception {
140130 Hello
141131 Hi!
142132 What is your name?""" ;
143- body = new TextGenerationRequest ( modelId , projectId , input , parameters );
133+
144134 mockServers .mockWatsonxBuilder (WireMockUtil .URL_WATSONX_CHAT_API , 200 )
145- .body (mapper .writeValueAsString (body ))
135+ .body (mapper .writeValueAsString (createRequest ( input ) ))
146136 .response ("""
147137 {
148138 "results": [
@@ -162,26 +152,16 @@ void extract_dialogue_test() throws Exception {
162152 @ Test
163153 void extract_dialogue_with_delimiter_test () throws Exception {
164154
165- LangChain4jWatsonxConfig .WatsonConfig watsonConfig = langchain4jWatsonConfig .defaultConfig ();
166- ChatModelConfig chatModelConfig = watsonConfig .chatModel ();
167- String modelId = langchain4jWatsonFixedRuntimeConfig .defaultConfig ().chatModel ().modelId ();
168155 String chatMemoryId = "userId_with_delimiter" ;
169- String projectId = watsonConfig .projectId ();
170- Parameters parameters = Parameters .builder ()
171- .decodingMethod (chatModelConfig .decodingMethod ())
172- .temperature (chatModelConfig .temperature ())
173- .minNewTokens (chatModelConfig .minNewTokens ())
174- .maxNewTokens (chatModelConfig .maxNewTokens ())
175- .build ();
176156
177157 var input = """
178158 You are a helpful assistant
179159 Context:
180160
181161 Hello""" ;
182- var body = new TextGenerationRequest ( modelId , projectId , input , parameters );
162+
183163 mockServers .mockWatsonxBuilder (WireMockUtil .URL_WATSONX_CHAT_API , 200 )
184- .body (mapper .writeValueAsString (body ))
164+ .body (mapper .writeValueAsString (createRequest ( input ) ))
185165 .response ("""
186166 {
187167 "results": [
@@ -204,9 +184,9 @@ void extract_dialogue_with_delimiter_test() throws Exception {
204184 Hello
205185 Hi!
206186 What is your name?""" ;
207- body = new TextGenerationRequest ( modelId , projectId , input , parameters );
187+
208188 mockServers .mockWatsonxBuilder (WireMockUtil .URL_WATSONX_CHAT_API , 200 )
209- .body (mapper .writeValueAsString (body ))
189+ .body (mapper .writeValueAsString (createRequest ( input ) ))
210190 .response ("""
211191 {
212192 "results": [
@@ -226,26 +206,16 @@ void extract_dialogue_with_delimiter_test() throws Exception {
226206 @ Test
227207 void extract_dialogue_with_all_params_test () throws Exception {
228208
229- LangChain4jWatsonxConfig .WatsonConfig watsonConfig = langchain4jWatsonConfig .defaultConfig ();
230- ChatModelConfig chatModelConfig = watsonConfig .chatModel ();
231- String modelId = langchain4jWatsonFixedRuntimeConfig .defaultConfig ().chatModel ().modelId ();
232209 String chatMemoryId = "userId_with_all_params" ;
233- String projectId = watsonConfig .projectId ();
234- Parameters parameters = Parameters .builder ()
235- .decodingMethod (chatModelConfig .decodingMethod ())
236- .temperature (chatModelConfig .temperature ())
237- .minNewTokens (chatModelConfig .minNewTokens ())
238- .maxNewTokens (chatModelConfig .maxNewTokens ())
239- .build ();
240210
241211 var input = """
242212 You are a helpful assistant
243213 Context:
244214
245215 Hello""" ;
246- var body = new TextGenerationRequest ( modelId , projectId , input , parameters );
216+
247217 mockServers .mockWatsonxBuilder (WireMockUtil .URL_WATSONX_CHAT_API , 200 )
248- .body (mapper .writeValueAsString (body ))
218+ .body (mapper .writeValueAsString (createRequest ( input ) ))
249219 .response ("""
250220 {
251221 "results": [
@@ -268,9 +238,9 @@ void extract_dialogue_with_all_params_test() throws Exception {
268238 Hello
269239 Hi!
270240 What is your name?""" ;
271- body = new TextGenerationRequest ( modelId , projectId , input , parameters );
241+
272242 mockServers .mockWatsonxBuilder (WireMockUtil .URL_WATSONX_CHAT_API , 200 )
273- .body (mapper .writeValueAsString (body ))
243+ .body (mapper .writeValueAsString (createRequest ( input ) ))
274244 .response ("""
275245 {
276246 "results": [
@@ -290,17 +260,7 @@ void extract_dialogue_with_all_params_test() throws Exception {
290260 @ Test
291261 void extract_dialogue_no_memory_test () throws Exception {
292262
293- LangChain4jWatsonxConfig .WatsonConfig watsonConfig = langchain4jWatsonConfig .defaultConfig ();
294- ChatModelConfig chatModelConfig = watsonConfig .chatModel ();
295- String modelId = langchain4jWatsonFixedRuntimeConfig .defaultConfig ().chatModel ().modelId ();
296263 String chatMemoryId = "userId_with_all_params" ;
297- String projectId = watsonConfig .projectId ();
298- Parameters parameters = Parameters .builder ()
299- .decodingMethod (chatModelConfig .decodingMethod ())
300- .temperature (chatModelConfig .temperature ())
301- .minNewTokens (chatModelConfig .minNewTokens ())
302- .maxNewTokens (chatModelConfig .maxNewTokens ())
303- .build ();
304264
305265 var input = """
306266 Context:
@@ -309,9 +269,9 @@ void extract_dialogue_no_memory_test() throws Exception {
309269 User: What is your name?
310270 Assistant: My name is AiBot
311271 Hello""" ;
312- var body = new TextGenerationRequest ( modelId , projectId , input , parameters );
272+
313273 mockServers .mockWatsonxBuilder (WireMockUtil .URL_WATSONX_CHAT_API , 200 )
314- .body (mapper .writeValueAsString (body ))
274+ .body (mapper .writeValueAsString (createRequest ( input ) ))
315275 .response ("""
316276 {
317277 "results": [
@@ -327,4 +287,20 @@ void extract_dialogue_no_memory_test() throws Exception {
327287
328288 noMemoryAiService .rephrase (chatMemoryStore .getMessages (chatMemoryId ), "Hello" );
329289 }
290+
291+ private TextGenerationRequest createRequest (String input ) {
292+ LangChain4jWatsonxConfig .WatsonConfig watsonConfig = langchain4jWatsonConfig .defaultConfig ();
293+ ChatModelConfig chatModelConfig = watsonConfig .chatModel ();
294+ String modelId = langchain4jWatsonFixedRuntimeConfig .defaultConfig ().chatModel ().modelId ();
295+ String projectId = watsonConfig .projectId ();
296+ Parameters parameters = Parameters .builder ()
297+ .decodingMethod (chatModelConfig .decodingMethod ())
298+ .temperature (chatModelConfig .temperature ())
299+ .minNewTokens (chatModelConfig .minNewTokens ())
300+ .maxNewTokens (chatModelConfig .maxNewTokens ())
301+ .timeLimit (10000L )
302+ .build ();
303+
304+ return new TextGenerationRequest (modelId , projectId , input , parameters );
305+ }
330306}
0 commit comments