@@ -315,6 +315,99 @@ describe("OpenAiHandler", () => {
315315 const callArgs = mockCreate . mock . calls [ 0 ] [ 0 ]
316316 expect ( callArgs . max_completion_tokens ) . toBe ( 4096 )
317317 } )
318+
319+ it ( "should include thinking parameter for GLM-4.6 when reasoning is enabled" , async ( ) => {
320+ const glm46Options : ApiHandlerOptions = {
321+ ...mockOptions ,
322+ openAiModelId : "glm-4.6" ,
323+ enableReasoningEffort : true ,
324+ openAiCustomModelInfo : {
325+ contextWindow : 200_000 ,
326+ maxTokens : 98_304 ,
327+ supportsPromptCache : true ,
328+ supportsReasoningBinary : true ,
329+ } ,
330+ }
331+ const glm46Handler = new OpenAiHandler ( glm46Options )
332+ const stream = glm46Handler . createMessage ( systemPrompt , messages )
333+ // Consume the stream to trigger the API call
334+ for await ( const _chunk of stream ) {
335+ }
336+ // Assert the mockCreate was called with thinking parameter
337+ expect ( mockCreate ) . toHaveBeenCalled ( )
338+ const callArgs = mockCreate . mock . calls [ 0 ] [ 0 ]
339+ expect ( callArgs . thinking ) . toEqual ( { type : "enabled" } )
340+ } )
341+
342+ it ( "should not include thinking parameter for GLM-4.6 when reasoning is disabled" , async ( ) => {
343+ const glm46NoReasoningOptions : ApiHandlerOptions = {
344+ ...mockOptions ,
345+ openAiModelId : "glm-4.6" ,
346+ enableReasoningEffort : false ,
347+ openAiCustomModelInfo : {
348+ contextWindow : 200_000 ,
349+ maxTokens : 98_304 ,
350+ supportsPromptCache : true ,
351+ supportsReasoningBinary : true ,
352+ } ,
353+ }
354+ const glm46NoReasoningHandler = new OpenAiHandler ( glm46NoReasoningOptions )
355+ const stream = glm46NoReasoningHandler . createMessage ( systemPrompt , messages )
356+ // Consume the stream to trigger the API call
357+ for await ( const _chunk of stream ) {
358+ }
359+ // Assert the mockCreate was called without thinking parameter
360+ expect ( mockCreate ) . toHaveBeenCalled ( )
361+ const callArgs = mockCreate . mock . calls [ 0 ] [ 0 ]
362+ expect ( callArgs . thinking ) . toBeUndefined ( )
363+ } )
364+
365+ it ( "should include thinking parameter for GLM-4.6 in non-streaming mode when reasoning is enabled" , async ( ) => {
366+ const glm46NonStreamingOptions : ApiHandlerOptions = {
367+ ...mockOptions ,
368+ openAiModelId : "glm-4.6" ,
369+ openAiStreamingEnabled : false ,
370+ enableReasoningEffort : true ,
371+ openAiCustomModelInfo : {
372+ contextWindow : 200_000 ,
373+ maxTokens : 98_304 ,
374+ supportsPromptCache : true ,
375+ supportsReasoningBinary : true ,
376+ } ,
377+ }
378+ const glm46NonStreamingHandler = new OpenAiHandler ( glm46NonStreamingOptions )
379+ const stream = glm46NonStreamingHandler . createMessage ( systemPrompt , messages )
380+ // Consume the stream to trigger the API call
381+ for await ( const _chunk of stream ) {
382+ }
383+ // Assert the mockCreate was called with thinking parameter
384+ expect ( mockCreate ) . toHaveBeenCalled ( )
385+ const callArgs = mockCreate . mock . calls [ 0 ] [ 0 ]
386+ expect ( callArgs . thinking ) . toEqual ( { type : "enabled" } )
387+ } )
388+
389+ it ( "should not include thinking parameter for non-GLM-4.6 models even with reasoning enabled" , async ( ) => {
390+ const nonGlmOptions : ApiHandlerOptions = {
391+ ...mockOptions ,
392+ openAiModelId : "gpt-4" ,
393+ enableReasoningEffort : true ,
394+ openAiCustomModelInfo : {
395+ contextWindow : 128_000 ,
396+ maxTokens : 4096 ,
397+ supportsPromptCache : false ,
398+ supportsReasoningBinary : true ,
399+ } ,
400+ }
401+ const nonGlmHandler = new OpenAiHandler ( nonGlmOptions )
402+ const stream = nonGlmHandler . createMessage ( systemPrompt , messages )
403+ // Consume the stream to trigger the API call
404+ for await ( const _chunk of stream ) {
405+ }
406+ // Assert the mockCreate was called without thinking parameter
407+ expect ( mockCreate ) . toHaveBeenCalled ( )
408+ const callArgs = mockCreate . mock . calls [ 0 ] [ 0 ]
409+ expect ( callArgs . thinking ) . toBeUndefined ( )
410+ } )
318411 } )
319412
320413 describe ( "error handling" , ( ) => {
0 commit comments