11import { test } from "node:test" ;
22import assert from "node:assert/strict" ;
3+ import OpenAI from "openai" ;
34import { buildThinkingRequestOptions } from "../common/openai-thinking" ;
45
56test ( "buildThinkingRequestOptions explicitly disables thinking" , ( ) => {
@@ -17,27 +18,60 @@ test("buildThinkingRequestOptions uses the same disabled payload for volces endp
1718test ( "buildThinkingRequestOptions enables thinking with default reasoning effort" , ( ) => {
1819 assert . deepEqual ( buildThinkingRequestOptions ( true , "https://api.deepseek.com" ) , {
1920 thinking : { type : "enabled" } ,
20- extra_body : { reasoning_effort : "max" } ,
21+ reasoning_effort : "max" ,
2122 } ) ;
2223} ) ;
2324
2425test ( "buildThinkingRequestOptions uses the same enabled payload for volces endpoints" , ( ) => {
2526 assert . deepEqual ( buildThinkingRequestOptions ( true , "https://ark.cn-beijing.volces.com/api/v3" ) , {
2627 thinking : { type : "enabled" } ,
27- extra_body : { reasoning_effort : "max" } ,
28+ reasoning_effort : "max" ,
2829 } ) ;
2930} ) ;
3031
3132test ( "buildThinkingRequestOptions accepts high reasoning effort" , ( ) => {
3233 assert . deepEqual ( buildThinkingRequestOptions ( true , "https://api.deepseek.com" , "high" ) , {
3334 thinking : { type : "enabled" } ,
34- extra_body : { reasoning_effort : "high" } ,
35+ reasoning_effort : "high" ,
3536 } ) ;
3637} ) ;
3738
3839test ( "buildThinkingRequestOptions accepts low reasoning effort" , ( ) => {
3940 assert . deepEqual ( buildThinkingRequestOptions ( true , "https://api.deepseek.com" , "low" ) , {
4041 thinking : { type : "enabled" } ,
41- extra_body : { reasoning_effort : "low" } ,
42+ reasoning_effort : "low" ,
4243 } ) ;
4344} ) ;
45+
46+ test ( "OpenAI SDK sends thinking options at the top level" , async ( ) => {
47+ let body : Record < string , unknown > = { } ;
48+ const client = new OpenAI ( {
49+ apiKey : "test-key" ,
50+ maxRetries : 0 ,
51+ fetch : async ( _url , init ) => {
52+ body = JSON . parse ( String ( init ?. body ) ) ;
53+ return new Response ( '{"choices":[]}' , { headers : { "content-type" : "application/json" } } ) ;
54+ } ,
55+ } ) ;
56+
57+ for ( const [ enabled , effort ] of [
58+ [ true , "low" ] ,
59+ [ true , "high" ] ,
60+ [ true , "max" ] ,
61+ [ true , undefined ] ,
62+ [ false , "max" ] ,
63+ ] as const ) {
64+ await client . chat . completions . create ( {
65+ model : "deepseek-flash" ,
66+ messages : [ { role : "user" , content : "hello" } ] ,
67+ ...buildThinkingRequestOptions ( enabled , undefined , effort ) ,
68+ } as OpenAI . Chat . Completions . ChatCompletionCreateParamsNonStreaming ) ;
69+
70+ assert . deepEqual ( body , {
71+ model : "deepseek-flash" ,
72+ messages : [ { role : "user" , content : "hello" } ] ,
73+ thinking : { type : enabled ? "enabled" : "disabled" } ,
74+ ...( enabled ? { reasoning_effort : effort ?? "max" } : { } ) ,
75+ } ) ;
76+ }
77+ } ) ;
0 commit comments