@@ -705,6 +705,35 @@ void testApplyThinkingModeDegradesForcedToolChoice() throws Throwable {
705705 assertEquals ("auto" , request .getParameters ().getToolChoice ());
706706 }
707707
708+ @ Test
709+ @ DisplayName ("DashScope chat model should ignore a null request when degrading" )
710+ void testDegradeForcedToolChoiceWithNullRequest () throws Throwable {
711+ DashScopeChatModel chatModel =
712+ DashScopeChatModel .builder ()
713+ .apiKey (mockApiKey )
714+ .modelName ("qwen-plus" )
715+ .enableThinking (true )
716+ .build ();
717+
718+ assertDoesNotThrow (() -> invokeDegradeForcedToolChoiceForThinkingMode (chatModel , null ));
719+ }
720+
721+ @ Test
722+ @ DisplayName ("DashScope chat model should ignore missing parameters when degrading" )
723+ void testDegradeForcedToolChoiceWithNullParameters () throws Throwable {
724+ DashScopeChatModel chatModel =
725+ DashScopeChatModel .builder ()
726+ .apiKey (mockApiKey )
727+ .modelName ("qwen-plus" )
728+ .enableThinking (true )
729+ .build ();
730+
731+ assertDoesNotThrow (
732+ () ->
733+ invokeDegradeForcedToolChoiceForThinkingMode (
734+ chatModel , DashScopeRequest .builder ().build ()));
735+ }
736+
708737 @ Test
709738 @ DisplayName ("DashScope chat model apply thinking mode with null" )
710739 void testApplyThinkingModeWithNull () {
@@ -1261,4 +1290,24 @@ private void invokeApplyThinkingMode(
12611290 throw e .getTargetException ();
12621291 }
12631292 }
1293+
1294+ /**
1295+ * Use reflection to invoke degradeForcedToolChoiceForThinkingMode.
1296+ *
1297+ * @param model the dashscope model
1298+ * @param request the dashscope API request DTO
1299+ * @throws Throwable throw the target exception
1300+ */
1301+ private void invokeDegradeForcedToolChoiceForThinkingMode (
1302+ DashScopeChatModel model , DashScopeRequest request ) throws Throwable {
1303+ try {
1304+ Method method =
1305+ DashScopeChatModel .class .getDeclaredMethod (
1306+ "degradeForcedToolChoiceForThinkingMode" , DashScopeRequest .class );
1307+ method .setAccessible (true );
1308+ method .invoke (model , request );
1309+ } catch (InvocationTargetException e ) {
1310+ throw e .getTargetException ();
1311+ }
1312+ }
12641313}
0 commit comments