@@ -65,8 +65,9 @@ func TestReasoningModeIntegration(t *testing.T) {
6565
6666	// Test case 3: Test addReasoningModeToRequestBody function 
6767	t .Run ("addReasoningModeToRequestBody adds correct fields" , func (t  * testing.T ) {
68+ 		// Test with DeepSeek model (which supports chat_template_kwargs) 
6869		originalRequest  :=  map [string ]interface {}{
69- 			"model" : "phi4 " ,
70+ 			"model" : "deepseek-v31 " ,
7071			"messages" : []map [string ]interface {}{
7172				{"role" : "user" , "content" : "What is 2 + 2?" },
7273			},
@@ -88,23 +89,23 @@ func TestReasoningModeIntegration(t *testing.T) {
8889			t .Fatalf ("Failed to unmarshal modified request: %v" , err )
8990		}
9091
91- 		// Check if chat_template_kwargs was added 
92+ 		// Check if chat_template_kwargs was added for DeepSeek model  
9293		chatTemplateKwargs , exists  :=  modifiedRequest ["chat_template_kwargs" ]
9394		if  ! exists  {
94- 			t .Error ("chat_template_kwargs not found in modified request" )
95+ 			t .Error ("chat_template_kwargs not found in modified request for DeepSeek model " )
9596		}
9697
97- 		// Check if thinking: true was set 
98+ 		// Check if thinking: true was set for DeepSeek model  
9899		if  kwargs , ok  :=  chatTemplateKwargs .(map [string ]interface {}); ok  {
99100			if  thinking , hasThinking  :=  kwargs ["thinking" ]; hasThinking  {
100101				if  thinkingBool , isBool  :=  thinking .(bool ); ! isBool  ||  ! thinkingBool  {
101- 					t .Errorf ("Expected thinking: true, got %v" , thinking )
102+ 					t .Errorf ("Expected thinking: true for DeepSeek model , got %v" , thinking )
102103				}
103104			} else  {
104- 				t .Error ("thinking field not found in chat_template_kwargs" )
105+ 				t .Error ("thinking field not found in chat_template_kwargs for DeepSeek model " )
105106			}
106107		} else  {
107- 			t .Errorf ("chat_template_kwargs is not a map, got %T" , chatTemplateKwargs )
108+ 			t .Errorf ("chat_template_kwargs is not a map for DeepSeek model , got %T" , chatTemplateKwargs )
108109		}
109110
110111		// Verify original fields are preserved 
@@ -114,24 +115,80 @@ func TestReasoningModeIntegration(t *testing.T) {
114115				t .Errorf ("Original field '%s' was lost" , field )
115116			}
116117		}
118+ 
119+ 		// Test with unsupported model (phi4) - should not add chat_template_kwargs 
120+ 		originalRequestPhi4  :=  map [string ]interface {}{
121+ 			"model" : "phi4" ,
122+ 			"messages" : []map [string ]interface {}{
123+ 				{"role" : "user" , "content" : "What is 2 + 2?" },
124+ 			},
125+ 			"stream" : false ,
126+ 		}
127+ 
128+ 		originalBodyPhi4 , err  :=  json .Marshal (originalRequestPhi4 )
129+ 		if  err  !=  nil  {
130+ 			t .Fatalf ("Failed to marshal phi4 request: %v" , err )
131+ 		}
132+ 
133+ 		modifiedBodyPhi4 , err  :=  router .setReasoningModeToRequestBody (originalBodyPhi4 , true )
134+ 		if  err  !=  nil  {
135+ 			t .Fatalf ("Failed to process phi4 request: %v" , err )
136+ 		}
137+ 
138+ 		var  modifiedRequestPhi4  map [string ]interface {}
139+ 		if  err  :=  json .Unmarshal (modifiedBodyPhi4 , & modifiedRequestPhi4 ); err  !=  nil  {
140+ 			t .Fatalf ("Failed to unmarshal phi4 request: %v" , err )
141+ 		}
142+ 
143+ 		// For phi4, chat_template_kwargs should not be added (since it's not supported) 
144+ 		if  _ , exists  :=  modifiedRequestPhi4 ["chat_template_kwargs" ]; exists  {
145+ 			t .Error ("chat_template_kwargs should not be added for unsupported model phi4" )
146+ 		}
147+ 
148+ 		// But reasoning_effort should still be set 
149+ 		if  reasoningEffort , exists  :=  modifiedRequestPhi4 ["reasoning_effort" ]; ! exists  {
150+ 			t .Error ("reasoning_effort should be set for phi4 model" )
151+ 		} else  if  reasoningEffort  !=  "high"  {
152+ 			t .Errorf ("Expected reasoning_effort: high for phi4 model, got %v" , reasoningEffort )
153+ 		}
117154	})
118155
119156	// Test case 4: Test getChatTemplateKwargs function 
120157	t .Run ("getChatTemplateKwargs returns correct values" , func (t  * testing.T ) {
121- 		// Test with reasoning enabled 
122- 		kwargs  :=  getChatTemplateKwargs (true )
158+ 		// Test with DeepSeek model and  reasoning enabled 
159+ 		kwargs  :=  getChatTemplateKwargs ("deepseek-v31" ,  true )
123160		if  kwargs  ==  nil  {
124- 			t .Error ("Expected non-nil kwargs for reasoning enabled" )
161+ 			t .Error ("Expected non-nil kwargs for DeepSeek model with  reasoning enabled" )
125162		}
126163
127164		if  thinking , ok  :=  kwargs ["thinking" ]; ! ok  ||  thinking  !=  true  {
128- 			t .Errorf ("Expected thinking: true, got %v" , thinking )
165+ 			t .Errorf ("Expected thinking: true for DeepSeek model, got %v" , thinking )
166+ 		}
167+ 
168+ 		// Test with DeepSeek model and reasoning disabled 
169+ 		kwargs  =  getChatTemplateKwargs ("deepseek-v31" , false )
170+ 		if  kwargs  ==  nil  {
171+ 			t .Error ("Expected non-nil kwargs for DeepSeek model with reasoning disabled" )
172+ 		}
173+ 
174+ 		if  thinking , ok  :=  kwargs ["thinking" ]; ! ok  ||  thinking  !=  false  {
175+ 			t .Errorf ("Expected thinking: false for DeepSeek model, got %v" , thinking )
176+ 		}
177+ 
178+ 		// Test with Qwen3 model and reasoning enabled 
179+ 		kwargs  =  getChatTemplateKwargs ("qwen3-7b" , true )
180+ 		if  kwargs  ==  nil  {
181+ 			t .Error ("Expected non-nil kwargs for Qwen3 model with reasoning enabled" )
182+ 		}
183+ 
184+ 		if  enableThinking , ok  :=  kwargs ["enable_thinking" ]; ! ok  ||  enableThinking  !=  true  {
185+ 			t .Errorf ("Expected enable_thinking: true for Qwen3 model, got %v" , enableThinking )
129186		}
130187
131- 		// Test with reasoning disabled  
132- 		kwargs  =  getChatTemplateKwargs (false )
188+ 		// Test with unknown model (should return nil)  
189+ 		kwargs  =  getChatTemplateKwargs ("unknown-model" ,  true )
133190		if  kwargs  !=  nil  {
134- 			t .Errorf ("Expected nil kwargs for reasoning disabled , got %v" , kwargs )
191+ 			t .Errorf ("Expected nil kwargs for unknown model , got %v" , kwargs )
135192		}
136193	})
137194
0 commit comments