@@ -9,13 +9,19 @@ import (
99
1010// shouldUseReasoningMode determines if reasoning mode should be enabled based on the query category 
1111func  (r  * OpenAIRouter ) shouldUseReasoningMode (query  string ) bool  {
12+ 	enabled , _  :=  r .getReasoningModeAndCategory (query )
13+ 	return  enabled 
14+ }
15+ 
16+ // getReasoningModeAndCategory determines if reasoning mode should be enabled and returns the category name 
17+ func  (r  * OpenAIRouter ) getReasoningModeAndCategory (query  string ) (bool , string ) {
1218	// Get the category for this query using the existing classification system 
1319	categoryName  :=  r .findCategoryForClassification (query )
1420
1521	// If no category was determined (empty string), default to no reasoning 
1622	if  categoryName  ==  ""  {
1723		log .Printf ("No category determined for query, defaulting to no reasoning mode" )
18- 		return  false 
24+ 		return  false ,  "" 
1925	}
2026
2127	// Normalize category name for consistent lookup 
@@ -30,13 +36,13 @@ func (r *OpenAIRouter) shouldUseReasoningMode(query string) bool {
3036			}
3137			log .Printf ("Reasoning mode decision: Category '%s' → %s" ,
3238				categoryName , reasoningStatus )
33- 			return  category .UseReasoning 
39+ 			return  category .UseReasoning ,  categoryName 
3440		}
3541	}
3642
3743	// If category not found in config, default to no reasoning 
3844	log .Printf ("Category '%s' not found in configuration, defaulting to no reasoning mode" , categoryName )
39- 	return  false 
45+ 	return  false ,  categoryName 
4046}
4147
4248// getChatTemplateKwargs returns the appropriate chat template kwargs based on model and reasoning mode 
@@ -62,7 +68,7 @@ func getChatTemplateKwargs(model string, useReasoning bool) map[string]interface
6268}
6369
6470// setReasoningModeToRequestBody adds chat_template_kwargs to the JSON request body 
65- func  (r  * OpenAIRouter ) setReasoningModeToRequestBody (requestBody  []byte , enabled  bool ) ([]byte , error ) {
71+ func  (r  * OpenAIRouter ) setReasoningModeToRequestBody (requestBody  []byte , enabled  bool ,  categoryName   string ) ([]byte , error ) {
6672	// Parse the JSON request body 
6773	var  requestMap  map [string ]interface {}
6874	if  err  :=  json .Unmarshal (requestBody , & requestMap ); err  !=  nil  {
@@ -91,8 +97,9 @@ func (r *OpenAIRouter) setReasoningModeToRequestBody(requestBody []byte, enabled
9197		originalReasoningEffort  =  "low" 
9298	}
9399	if  enabled  {
94- 		// TODO: make this configurable 
95- 		requestMap ["reasoning_effort" ] =  "high" 
100+ 		// Use configurable reasoning effort based on category 
101+ 		effort  :=  r .getReasoningEffort (categoryName )
102+ 		requestMap ["reasoning_effort" ] =  effort 
96103	} else  {
97104		requestMap ["reasoning_effort" ] =  originalReasoningEffort 
98105	}
@@ -170,3 +177,30 @@ func (r *OpenAIRouter) LogReasoningConfigurationSummary() {
170177
171178	log .Printf ("Reasoning mode summary: %d/%d categories have reasoning enabled" , enabledCount , len (r .Config .Categories ))
172179}
180+ 
181+ // getReasoningEffort returns the reasoning effort level for a given category 
182+ func  (r  * OpenAIRouter ) getReasoningEffort (categoryName  string ) string  {
183+ 	// Handle case where Config is nil (e.g., in tests) 
184+ 	if  r .Config  ==  nil  {
185+ 		return  "medium" 
186+ 	}
187+ 
188+ 	// Find the category configuration 
189+ 	for  _ , category  :=  range  r .Config .Categories  {
190+ 		if  category .Name  ==  categoryName  {
191+ 			// Use category-specific effort if configured 
192+ 			if  category .ReasoningEffort  !=  ""  {
193+ 				return  category .ReasoningEffort 
194+ 			}
195+ 			break 
196+ 		}
197+ 	}
198+ 
199+ 	// Fall back to global default if configured 
200+ 	if  r .Config .DefaultReasoningEffort  !=  ""  {
201+ 		return  r .Config .DefaultReasoningEffort 
202+ 	}
203+ 
204+ 	// Final fallback to "medium" as a reasonable default 
205+ 	return  "medium" 
206+ }
0 commit comments