2828import io .agentscope .core .formatter .dashscope .dto .DashScopeRequest ;
2929import io .agentscope .core .formatter .dashscope .dto .DashScopeResponse ;
3030import java .util .ArrayList ;
31+ import java .util .HashMap ;
3132import java .util .List ;
33+ import java .util .Map ;
3234import okhttp3 .mockwebserver .MockResponse ;
3335import okhttp3 .mockwebserver .MockWebServer ;
3436import okhttp3 .mockwebserver .RecordedRequest ;
@@ -137,7 +139,7 @@ void testCallTextGenerationApi() throws Exception {
137139
138140 DashScopeRequest request = createTestRequest ("qwen-plus" , "Hello" );
139141
140- DashScopeResponse response = client .call (request );
142+ DashScopeResponse response = client .call (request , null , null , null );
141143
142144 assertNotNull (response );
143145 assertEquals ("test-request-id" , response .getRequestId ());
@@ -181,7 +183,7 @@ void testCallMultimodalApi() throws Exception {
181183
182184 DashScopeRequest request = createTestRequest ("qwen-vl-max" , "What's in this image?" );
183185
184- DashScopeResponse response = client .call (request );
186+ DashScopeResponse response = client .call (request , null , null , null );
185187
186188 assertNotNull (response );
187189 assertEquals ("multimodal-request-id" , response .getRequestId ());
@@ -209,7 +211,7 @@ void testStreamTextGenerationApi() {
209211 DashScopeRequest request = createTestRequest ("qwen-plus" , "Hi" );
210212
211213 List <DashScopeResponse > responses = new ArrayList <>();
212- StepVerifier .create (client .stream (request ))
214+ StepVerifier .create (client .stream (request , null , null , null ))
213215 .recordWith (() -> responses )
214216 .expectNextCount (2 )
215217 .verifyComplete ();
@@ -239,7 +241,7 @@ void testStreamMultimodalApi() {
239241
240242 DashScopeRequest request = createTestRequest ("qwen-vl-max" , "Describe image" );
241243
242- StepVerifier .create (client .stream (request ))
244+ StepVerifier .create (client .stream (request , null , null , null ))
243245 .expectNextMatches (
244246 r ->
245247 "I see"
@@ -273,7 +275,7 @@ void testApiErrorHandling() {
273275 DashScopeHttpClient .DashScopeHttpException exception =
274276 assertThrows (
275277 DashScopeHttpClient .DashScopeHttpException .class ,
276- () -> client .call (request ));
278+ () -> client .call (request , null , null , null ));
277279
278280 assertTrue (exception .getMessage ().contains ("Invalid API key" ));
279281 }
@@ -291,7 +293,7 @@ void testHttpErrorHandling() {
291293 DashScopeHttpClient .DashScopeHttpException exception =
292294 assertThrows (
293295 DashScopeHttpClient .DashScopeHttpException .class ,
294- () -> client .call (request ));
296+ () -> client .call (request , null , null , null ));
295297
296298 assertEquals (500 , exception .getStatusCode ());
297299 }
@@ -322,7 +324,7 @@ void testRequestHeaders() throws Exception {
322324 .setHeader ("Content-Type" , "application/json" ));
323325
324326 DashScopeRequest request = createTestRequest ("qwen-plus" , "test" );
325- client .call (request );
327+ client .call (request , null , null , null );
326328
327329 RecordedRequest recorded = mockServer .takeRequest ();
328330 assertEquals ("Bearer test-api-key" , recorded .getHeader ("Authorization" ));
@@ -339,7 +341,7 @@ void testStreamingRequestHeaders() throws Exception {
339341 .setHeader ("Content-Type" , "text/event-stream" ));
340342
341343 DashScopeRequest request = createTestRequest ("qwen-plus" , "test" );
342- client .stream (request ).blockLast ();
344+ client .stream (request , null , null , null ).blockLast ();
343345
344346 RecordedRequest recorded = mockServer .takeRequest ();
345347 assertEquals ("enable" , recorded .getHeader ("X-DashScope-SSE" ));
@@ -482,6 +484,61 @@ void testHeaderOverride() throws Exception {
482484 assertEquals ("application/json; charset=utf-8" , recorded .getHeader ("Content-Type" ));
483485 }
484486
487+ @ Test
488+ void testCallAdditionalHeadersAndParams () throws Exception {
489+ mockServer .enqueue (
490+ new MockResponse ()
491+ .setResponseCode (200 )
492+ .setBody ("{\" request_id\" :\" test\" ,\" output\" :{\" choices\" :[]}}" )
493+ .setHeader ("Content-Type" , "application/json" ));
494+
495+ DashScopeRequest request = createTestRequest ("qwen-plus" , "test" );
496+ // Override the Content-Type header
497+ Map <String , String > additionalHeaders = new HashMap <>();
498+ additionalHeaders .put ("custom" , "custom-header" );
499+ Map <String , Object > additionalBodyParams = new HashMap <>();
500+ additionalBodyParams .put ("custom" , "custom-body" );
501+ Map <String , String > additionalQueryParams = new HashMap <>();
502+ additionalQueryParams .put ("custom" , "custom-query" );
503+
504+ client .call (request , additionalHeaders , additionalBodyParams , additionalQueryParams );
505+
506+ RecordedRequest recorded = mockServer .takeRequest ();
507+ assertEquals ("custom-header" , recorded .getHeader ("custom" ));
508+ assertEquals (
509+ DashScopeHttpClient .TEXT_GENERATION_ENDPOINT + "?custom=custom-query" ,
510+ recorded .getPath ());
511+ assertTrue (recorded .getBody ().readUtf8 ().contains ("\" custom\" :\" custom-body\" " ));
512+ }
513+
514+ @ Test
515+ void testStreamAdditionalHeadersAndParams () throws Exception {
516+ mockServer .enqueue (
517+ new MockResponse ()
518+ .setResponseCode (200 )
519+ .setBody ("{\" request_id\" :\" test\" ,\" output\" :{\" choices\" :[]}}" )
520+ .setHeader ("Content-Type" , "application/json" ));
521+
522+ DashScopeRequest request = createTestRequest ("qwen-plus" , "test" );
523+ // Override the Content-Type header
524+ Map <String , String > additionalHeaders = new HashMap <>();
525+ additionalHeaders .put ("custom" , "custom-header" );
526+ Map <String , Object > additionalBodyParams = new HashMap <>();
527+ additionalBodyParams .put ("custom" , "custom-value" );
528+ Map <String , String > additionalQueryParams = new HashMap <>();
529+ additionalQueryParams .put ("custom" , "custom-value" );
530+
531+ client .stream (request , additionalHeaders , additionalBodyParams , additionalQueryParams )
532+ .blockLast ();
533+
534+ RecordedRequest recorded = mockServer .takeRequest ();
535+ assertEquals ("custom-header" , recorded .getHeader ("custom" ));
536+ assertEquals (
537+ DashScopeHttpClient .TEXT_GENERATION_ENDPOINT + "?custom=custom-value" ,
538+ recorded .getPath ());
539+ assertTrue (recorded .getBody ().readUtf8 ().contains ("\" custom\" :\" custom-value\" " ));
540+ }
541+
485542 // ==================== DashScopeHttpException Tests ====================
486543
487544 @ Test
0 commit comments