@@ -199,10 +199,42 @@ requestBody := buildRequestBody(model, messages, useReasoning, stream)
199199func TestAddReasoningModeToRequestBody (t * testing.T ) {
200200 fmt .Println ("=== Testing addReasoningModeToRequestBody Function ===" )
201201
202- // Create a mock router with minimal config
203- router := & OpenAIRouter {}
202+ // Create a mock router with family-based reasoning config
203+ router := & OpenAIRouter {
204+ Config : & config.RouterConfig {
205+ DefaultReasoningEffort : "medium" ,
206+ ReasoningFamilies : map [string ]config.ReasoningFamilyConfig {
207+ "deepseek" : {
208+ Type : "chat_template_kwargs" ,
209+ Parameter : "thinking" ,
210+ },
211+ "qwen3" : {
212+ Type : "chat_template_kwargs" ,
213+ Parameter : "enable_thinking" ,
214+ },
215+ "gpt-oss" : {
216+ Type : "reasoning_effort" ,
217+ Parameter : "reasoning_effort" ,
218+ },
219+ },
220+ ModelConfig : map [string ]config.ModelParams {
221+ "deepseek-v31" : {
222+ ReasoningFamily : "deepseek" ,
223+ },
224+ "qwen3-model" : {
225+ ReasoningFamily : "qwen3" ,
226+ },
227+ "gpt-oss-model" : {
228+ ReasoningFamily : "gpt-oss" ,
229+ },
230+ "phi4" : {
231+ // No reasoning family - doesn't support reasoning
232+ },
233+ },
234+ },
235+ }
204236
205- // Test case 1: Basic request body
237+ // Test case 1: Basic request body with model that has NO reasoning support (phi4)
206238 originalRequest := map [string ]interface {}{
207239 "model" : "phi4" ,
208240 "messages" : []map [string ]interface {}{
@@ -235,29 +267,76 @@ func TestAddReasoningModeToRequestBody(t *testing.T) {
235267 return
236268 }
237269
238- // Check if chat_template_kwargs was added
239- if chatTemplateKwargs , exists := modifiedRequest ["chat_template_kwargs" ]; exists {
270+ // Check that chat_template_kwargs was NOT added for phi4 (since it has no reasoning_family)
271+ if _ , exists := modifiedRequest ["chat_template_kwargs" ]; exists {
272+ fmt .Println ("ERROR: chat_template_kwargs should not be added for phi4 (no reasoning family configured)" )
273+ } else {
274+ fmt .Println ("SUCCESS: chat_template_kwargs correctly not added for phi4 (no reasoning support)" )
275+ }
276+
277+ // Check that reasoning_effort was NOT added for phi4
278+ if _ , exists := modifiedRequest ["reasoning_effort" ]; exists {
279+ fmt .Println ("ERROR: reasoning_effort should not be added for phi4 (no reasoning family configured)" )
280+ } else {
281+ fmt .Println ("SUCCESS: reasoning_effort correctly not added for phi4 (no reasoning support)" )
282+ }
283+
284+ // Test case 2: Request with model that HAS reasoning support (deepseek-v31)
285+ fmt .Println ("\n --- Test Case 2: Model with reasoning support ---" )
286+ deepseekRequest := map [string ]interface {}{
287+ "model" : "deepseek-v31" ,
288+ "messages" : []map [string ]interface {}{
289+ {"role" : "user" , "content" : "What is 2 + 2?" },
290+ },
291+ "stream" : false ,
292+ }
293+
294+ deepseekBody , err := json .Marshal (deepseekRequest )
295+ if err != nil {
296+ fmt .Printf ("Error marshaling deepseek request: %v\n " , err )
297+ return
298+ }
299+
300+ fmt .Printf ("Original deepseek request:\n %s\n \n " , string (deepseekBody ))
301+
302+ // Add reasoning mode to DeepSeek model
303+ modifiedDeepseekBody , err := router .setReasoningModeToRequestBody (deepseekBody , true , "math" )
304+ if err != nil {
305+ fmt .Printf ("Error adding reasoning mode to deepseek: %v\n " , err )
306+ return
307+ }
308+
309+ fmt .Printf ("Modified deepseek request with reasoning:\n %s\n \n " , string (modifiedDeepseekBody ))
310+
311+ var modifiedDeepseekRequest map [string ]interface {}
312+ if err := json .Unmarshal (modifiedDeepseekBody , & modifiedDeepseekRequest ); err != nil {
313+ fmt .Printf ("Error unmarshaling modified deepseek request: %v\n " , err )
314+ return
315+ }
316+
317+ // Check that chat_template_kwargs WAS added for deepseek-v31
318+ if chatTemplateKwargs , exists := modifiedDeepseekRequest ["chat_template_kwargs" ]; exists {
240319 if kwargs , ok := chatTemplateKwargs .(map [string ]interface {}); ok {
241320 if thinking , hasThinking := kwargs ["thinking" ]; hasThinking {
242321 if thinkingBool , isBool := thinking .(bool ); isBool && thinkingBool {
243- fmt .Println ("✅ SUCCESS: chat_template_kwargs with thinking: true was correctly added" )
322+ fmt .Println ("SUCCESS: chat_template_kwargs with thinking: true correctly added for deepseek-v31 " )
244323 } else {
245- fmt .Printf ("❌ ERROR: thinking value is not true, got: %v\n " , thinking )
324+ fmt .Printf ("ERROR: thinking value is not true for deepseek-v31 , got: %v\n " , thinking )
246325 }
247326 } else {
248- fmt .Println ("❌ ERROR: thinking field not found in chat_template_kwargs" )
327+ fmt .Println ("ERROR: thinking field not found in chat_template_kwargs for deepseek-v31 " )
249328 }
250329 } else {
251- fmt .Printf ("❌ ERROR: chat_template_kwargs is not a map, got: %T\n " , chatTemplateKwargs )
330+ fmt .Printf ("ERROR: chat_template_kwargs is not a map for deepseek-v31 , got: %T\n " , chatTemplateKwargs )
252331 }
253332 } else {
254- fmt .Println ("❌ ERROR: chat_template_kwargs not found in modified request " )
333+ fmt .Println ("ERROR: chat_template_kwargs not found for deepseek-v31 (should be present) " )
255334 }
256335
257- // Test case 2 : Request with existing fields
258- fmt .Println ("\n --- Test Case 2 : Request with existing fields ---" )
336+ // Test case 3 : Request with existing fields
337+ fmt .Println ("\n --- Test Case 3 : Request with existing fields ---" )
259338 complexRequest := map [string ]interface {}{
260- "model" : "phi4 " ,
339+ "model" : "deepseek-v31 " ,
261340 "messages" : []map [string ]interface {}{
262341 {"role" : "system" , "content" : "You are a helpful assistant" },
263342 {"role" : "user" , "content" : "Solve x^2 + 5x + 6 = 0" },
@@ -290,20 +369,20 @@ func TestAddReasoningModeToRequestBody(t *testing.T) {
290369 allFieldsPreserved := true
291370 for _ , field := range originalFields {
292371 if _ , exists := modifiedComplexRequest [field ]; ! exists {
293- fmt .Printf ("❌ ERROR: Original field '%s' was lost\n " , field )
372+ fmt .Printf ("ERROR: Original field '%s' was lost\n " , field )
294373 allFieldsPreserved = false
295374 }
296375 }
297376
298377 if allFieldsPreserved {
299- fmt .Println ("✅ SUCCESS: All original fields preserved" )
378+ fmt .Println ("SUCCESS: All original fields preserved" )
300379 }
301380
302- // Verify chat_template_kwargs was added
381+ // Verify chat_template_kwargs was added for deepseek-v31
303382 if _ , exists := modifiedComplexRequest ["chat_template_kwargs" ]; exists {
304- fmt .Println ("✅ SUCCESS: chat_template_kwargs added to complex request" )
305- fmt .Printf ("Final modified request:\n %s\n " , string (modifiedComplexBody ))
383+ fmt .Println ("SUCCESS: chat_template_kwargs added to complex deepseek request" )
384+ fmt .Printf ("Final modified deepseek request:\n %s\n " , string (modifiedComplexBody ))
306385 } else {
307- fmt .Println ("❌ ERROR: chat_template_kwargs not added to complex request" )
386+ fmt .Println ("ERROR: chat_template_kwargs not added to complex deepseek request" )
308387 }
309388}
0 commit comments