@@ -503,6 +503,7 @@ describe("ChutesHandler", () => {
503503 temperature : 0.6 ,
504504 stream : true ,
505505 stream_options : { include_usage : true } ,
506+ reasoning_effort : "medium" , // DeepSeek R1 now supports reasoning effort with default "medium"
506507 } ) ,
507508 )
508509 } )
@@ -540,7 +541,6 @@ describe("ChutesHandler", () => {
540541 stream : true ,
541542 stream_options : { include_usage : true } ,
542543 } ) ,
543- undefined ,
544544 )
545545 } )
546546
@@ -563,4 +563,155 @@ describe("ChutesHandler", () => {
563563 const model = handlerWithModel . getModel ( )
564564 expect ( model . info . temperature ) . toBe ( 0.5 )
565565 } )
566+
567+ describe ( "reasoning effort support" , ( ) => {
568+ it ( "should pass reasoning effort for models that support it" , async ( ) => {
569+ const modelId : ChutesModelId = "deepseek-ai/DeepSeek-R1"
570+
571+ // Clear previous mocks and set up new implementation
572+ mockCreate . mockClear ( )
573+ mockCreate . mockImplementationOnce ( async ( ) => ( {
574+ [ Symbol . asyncIterator ] : async function * ( ) {
575+ yield { choices : [ { delta : { content : "test" } } ] , usage : null }
576+ } ,
577+ } ) )
578+
579+ const handlerWithModel = new ChutesHandler ( {
580+ apiModelId : modelId ,
581+ chutesApiKey : "test-chutes-api-key" ,
582+ enableReasoningEffort : true ,
583+ reasoningEffort : "high" ,
584+ } )
585+
586+ const systemPrompt = "Test system prompt"
587+ const messages : Anthropic . Messages . MessageParam [ ] = [ { role : "user" , content : "Test message" } ]
588+
589+ const generator = handlerWithModel . createMessage ( systemPrompt , messages )
590+ await generator . next ( )
591+
592+ expect ( mockCreate ) . toHaveBeenCalledWith (
593+ expect . objectContaining ( {
594+ reasoning_effort : "high" ,
595+ } ) ,
596+ )
597+ } )
598+
599+ it ( "should not pass reasoning effort for models that don't support it" , async ( ) => {
600+ const modelId : ChutesModelId = "unsloth/Llama-3.3-70B-Instruct"
601+
602+ // Clear previous mocks and set up new implementation
603+ mockCreate . mockClear ( )
604+ mockCreate . mockImplementationOnce ( async ( ) => ( {
605+ [ Symbol . asyncIterator ] : async function * ( ) {
606+ yield { choices : [ { delta : { content : "test" } } ] , usage : null }
607+ } ,
608+ } ) )
609+
610+ const handlerWithModel = new ChutesHandler ( {
611+ apiModelId : modelId ,
612+ chutesApiKey : "test-chutes-api-key" ,
613+ enableReasoningEffort : true ,
614+ reasoningEffort : "high" ,
615+ } )
616+
617+ const systemPrompt = "Test system prompt"
618+ const messages : Anthropic . Messages . MessageParam [ ] = [ { role : "user" , content : "Test message" } ]
619+
620+ const generator = handlerWithModel . createMessage ( systemPrompt , messages )
621+ await generator . next ( )
622+
623+ const callArgs = mockCreate . mock . calls [ 0 ] [ 0 ]
624+ expect ( callArgs ) . not . toHaveProperty ( "reasoning_effort" )
625+ } )
626+
627+ it ( "should use model default reasoning effort when not explicitly set" , async ( ) => {
628+ const modelId : ChutesModelId = "meituan-longcat/LongCat-Flash-Thinking-FP8"
629+
630+ // Clear previous mocks and set up new implementation
631+ mockCreate . mockClear ( )
632+ mockCreate . mockImplementationOnce ( async ( ) => ( {
633+ [ Symbol . asyncIterator ] : async function * ( ) {
634+ yield { choices : [ { delta : { content : "test" } } ] , usage : null }
635+ } ,
636+ } ) )
637+
638+ const handlerWithModel = new ChutesHandler ( {
639+ apiModelId : modelId ,
640+ chutesApiKey : "test-chutes-api-key" ,
641+ // Not setting enableReasoningEffort or reasoningEffort to test model defaults
642+ } )
643+
644+ const systemPrompt = "Test system prompt"
645+ const messages : Anthropic . Messages . MessageParam [ ] = [ { role : "user" , content : "Test message" } ]
646+
647+ const generator = handlerWithModel . createMessage ( systemPrompt , messages )
648+ await generator . next ( )
649+
650+ // Since we don't set enableReasoningEffort to true, and just rely on model defaults,
651+ // the reasoning_effort will be included because the model has a default reasoningEffort
652+ expect ( mockCreate ) . toHaveBeenCalledWith (
653+ expect . objectContaining ( {
654+ reasoning_effort : "medium" , // Should use the model's default
655+ } ) ,
656+ )
657+ } )
658+
659+ it ( "should not pass reasoning effort when disabled" , async ( ) => {
660+ const modelId : ChutesModelId = "deepseek-ai/DeepSeek-R1"
661+
662+ // Clear previous mocks and set up new implementation
663+ mockCreate . mockClear ( )
664+ mockCreate . mockImplementationOnce ( async ( ) => ( {
665+ [ Symbol . asyncIterator ] : async function * ( ) {
666+ yield { choices : [ { delta : { content : "test" } } ] , usage : null }
667+ } ,
668+ } ) )
669+
670+ const handlerWithModel = new ChutesHandler ( {
671+ apiModelId : modelId ,
672+ chutesApiKey : "test-chutes-api-key" ,
673+ enableReasoningEffort : false ,
674+ reasoningEffort : "high" ,
675+ } )
676+
677+ const systemPrompt = "Test system prompt"
678+ const messages : Anthropic . Messages . MessageParam [ ] = [ { role : "user" , content : "Test message" } ]
679+
680+ const generator = handlerWithModel . createMessage ( systemPrompt , messages )
681+ await generator . next ( )
682+
683+ const callArgs = mockCreate . mock . calls [ 0 ] [ 0 ]
684+ expect ( callArgs ) . not . toHaveProperty ( "reasoning_effort" )
685+ } )
686+
687+ it ( "should pass reasoning effort for thinking models" , async ( ) => {
688+ const modelId : ChutesModelId = "Qwen/Qwen3-235B-A22B-Thinking-2507"
689+
690+ // Clear previous mocks and set up new implementation
691+ mockCreate . mockClear ( )
692+ mockCreate . mockImplementationOnce ( async ( ) => ( {
693+ [ Symbol . asyncIterator ] : async function * ( ) {
694+ yield { choices : [ { delta : { content : "test" } } ] , usage : null }
695+ } ,
696+ } ) )
697+
698+ const handlerWithModel = new ChutesHandler ( {
699+ apiModelId : modelId ,
700+ chutesApiKey : "test-chutes-api-key" ,
701+ reasoningEffort : "low" , // Just set the reasoning effort, no need for enableReasoningEffort
702+ } )
703+
704+ const systemPrompt = "Test system prompt"
705+ const messages : Anthropic . Messages . MessageParam [ ] = [ { role : "user" , content : "Test message" } ]
706+
707+ const generator = handlerWithModel . createMessage ( systemPrompt , messages )
708+ await generator . next ( )
709+
710+ expect ( mockCreate ) . toHaveBeenCalledWith (
711+ expect . objectContaining ( {
712+ reasoning_effort : "low" ,
713+ } ) ,
714+ )
715+ } )
716+ } )
566717} )
0 commit comments