18
18
AnthropicMessagesTool ,
19
19
AnthropicMessagesToolChoice ,
20
20
AnthropicSystemMessageContent ,
21
+ AnthropicThinkingParam ,
21
22
)
22
23
from litellm .types .llms .openai import (
24
+ REASONING_EFFORT ,
23
25
AllMessageValues ,
24
26
ChatCompletionCachedContent ,
25
27
ChatCompletionSystemMessage ,
@@ -94,6 +96,7 @@ def get_supported_openai_params(self, model: str):
94
96
"parallel_tool_calls" ,
95
97
"response_format" ,
96
98
"user" ,
99
+ "reasoning_effort" ,
97
100
]
98
101
99
102
if "claude-3-7-sonnet" in model :
@@ -291,6 +294,21 @@ def _map_stop_sequences(
291
294
new_stop = new_v
292
295
return new_stop
293
296
297
+ @staticmethod
298
+ def _map_reasoning_effort (
299
+ reasoning_effort : Optional [Union [REASONING_EFFORT , str ]]
300
+ ) -> Optional [AnthropicThinkingParam ]:
301
+ if reasoning_effort is None :
302
+ return None
303
+ elif reasoning_effort == "low" :
304
+ return AnthropicThinkingParam (type = "enabled" , budget_tokens = 1024 )
305
+ elif reasoning_effort == "medium" :
306
+ return AnthropicThinkingParam (type = "enabled" , budget_tokens = 2048 )
307
+ elif reasoning_effort == "high" :
308
+ return AnthropicThinkingParam (type = "enabled" , budget_tokens = 4096 )
309
+ else :
310
+ raise ValueError (f"Unmapped reasoning effort: { reasoning_effort } " )
311
+
294
312
def map_openai_params (
295
313
self ,
296
314
non_default_params : dict ,
@@ -302,10 +320,6 @@ def map_openai_params(
302
320
non_default_params = non_default_params
303
321
)
304
322
305
- ## handle thinking tokens
306
- self .update_optional_params_with_thinking_tokens (
307
- non_default_params = non_default_params , optional_params = optional_params
308
- )
309
323
for param , value in non_default_params .items ():
310
324
if param == "max_tokens" :
311
325
optional_params ["max_tokens" ] = value
@@ -370,7 +384,15 @@ def map_openai_params(
370
384
optional_params ["metadata" ] = {"user_id" : value }
371
385
if param == "thinking" :
372
386
optional_params ["thinking" ] = value
387
+ elif param == "reasoning_effort" and isinstance (value , str ):
388
+ optional_params ["thinking" ] = AnthropicConfig ._map_reasoning_effort (
389
+ value
390
+ )
373
391
392
+ ## handle thinking tokens
393
+ self .update_optional_params_with_thinking_tokens (
394
+ non_default_params = non_default_params , optional_params = optional_params
395
+ )
374
396
return optional_params
375
397
376
398
def _create_json_tool_call_for_response_format (
0 commit comments