@@ -64,9 +64,10 @@ def completion_with_backoff(
64
64
formatted_messages = [{"role" : message .role , "content" : message .content } for message in messages ]
65
65
66
66
# Tune reasoning models arguments
67
- if model_name . startswith ( "o1" ) or model_name . startswith ( "o3" ):
67
+ if is_openai_reasoning_model ( model_name , api_base_url ):
68
68
temperature = 1
69
- model_kwargs ["reasoning_effort" ] = "medium"
69
+ reasoning_effort = "medium" if deepthought else "low"
70
+ model_kwargs ["reasoning_effort" ] = reasoning_effort
70
71
71
72
model_kwargs ["stream_options" ] = {"include_usage" : True }
72
73
if os .getenv ("KHOJ_LLM_SEED" ):
@@ -162,12 +163,13 @@ def llm_thread(
162
163
163
164
formatted_messages = [{"role" : message .role , "content" : message .content } for message in messages ]
164
165
165
- # Tune reasoning models arguments
166
- if model_name . startswith ( "o1" ) or model_name . startswith ( "o3" ):
166
+ # Configure thinking for openai reasoning models
167
+ if is_openai_reasoning_model ( model_name , api_base_url ):
167
168
temperature = 1
168
- model_kwargs ["reasoning_effort" ] = "medium"
169
+ reasoning_effort = "medium" if deepthought else "low"
170
+ model_kwargs ["reasoning_effort" ] = reasoning_effort
171
+ model_kwargs .pop ("stop" , None ) # Remove unsupported stop param for reasoning models
169
172
170
- if model_name .startswith ("o3" ):
171
173
# Get the first system message and add the string `Formatting re-enabled` to it.
172
174
# See https://platform.openai.com/docs/guides/reasoning-best-practices
173
175
if len (formatted_messages ) > 0 :
@@ -257,3 +259,10 @@ def get_openai_api_json_support(model_name: str, api_base_url: str = None) -> Js
257
259
if host == "api.deepinfra.com" :
258
260
return JsonSupport .OBJECT
259
261
return JsonSupport .SCHEMA
262
+
263
+
264
+ def is_openai_reasoning_model (model_name : str , api_base_url : str = None ) -> bool :
265
+ """
266
+ Check if the model is an OpenAI reasoning model
267
+ """
268
+ return model_name .startswith ("o" ) and (api_base_url is None or api_base_url .startswith ("https://api.openai.com/v1" ))
0 commit comments