@@ -602,6 +602,55 @@ def make_messages(
602602 messages = messages [:1 ] + messages [- keep_n :]
603603 return messages
604604
605+ @staticmethod
606+ def get_reasoning (response_or_ret , return_if_missing = None ) -> str | None :
607+ """
608+ Extract the reasoning text if the model provided it, otherwise return None or "" (depending on the
609+ return_if_missing parameter).
610+ This takes either the return value which must contain the response or the response directly.
611+ """
612+ if "response" in response_or_ret and "error" in response_or_ret and "ok" in response_or_ret :
613+ response = response_or_ret ["response" ]
614+ else :
615+ response = response_or_ret
616+ if not hasattr (response , "choices" ):
617+ return return_if_missing
618+ choices = response .choices
619+ choice0 = choices [0 ]
620+ message = choice0 .message
621+ if hasattr (message , "reasoning_content" ):
622+ return message .reasoning_content
623+ else :
624+ return return_if_missing
625+
626+
627+
628+ @staticmethod
629+ def get_thinkingblocks (response_or_ret , return_if_missing = None ) -> list [str ]| None :
630+ """
631+ Extract the thining blocks if the model provided it, otherwise return None or "" (depending on the
632+ return_if_missing parameter).
633+ This takes either the return value which must contain the response or the response directly.
634+ """
635+ if "response" in response_or_ret and "error" in response_or_ret and "ok" in response_or_ret :
636+ response = response_or_ret ["response" ]
637+ else :
638+ response = response_or_ret
639+ if not hasattr (response , "choices" ):
640+ return return_if_missing
641+ choices = response .choices
642+ choice0 = choices [0 ]
643+ message = choice0 .message
644+ if hasattr (message , "thinking_blocks" ):
645+ blocks = []
646+ for i , d in enumerate (message .thinking_blocks ):
647+ t = d ["thinking" ]
648+ blocks .append (t )
649+ return blocks
650+ else :
651+ return return_if_missing
652+
653+
605654 @staticmethod
606655 def make_tooling (functions : Union [Callable , List [Callable ]]) -> List [Dict ]:
607656 """
@@ -821,6 +870,9 @@ def query(
821870 logger .debug (f"Received recursive call info: { recursive_call_info } " )
822871 if kwargs :
823872 completion_kwargs .update (dict_except (kwargs , KNOWN_LLM_CONFIG_FIELDS , ignore_underscored = True ))
873+ # we default to drop_params=False by default, but do not set this if the parameter is already set
874+ if "drop_params" not in completion_kwargs :
875+ completion_kwargs ["drop_params" ] = False
824876 if debug :
825877 logger .debug (f"calling query with completion kwargs: { cleaned_args (completion_kwargs )} " )
826878 # if we have min_delay set, we look at the _last_request_time for the LLM and caclulate the time
@@ -858,7 +910,6 @@ def cost_callback(kwargs, completion_response, start_time, end_time):
858910 response = litellm .completion (
859911 model = llm ["llm" ],
860912 messages = messages ,
861- drop_params = False , # we do not drop, so typos in the query call can be detected easier!
862913 ** completion_kwargs )
863914 logger .debug (f"Received response from litellm" )
864915 if via_streaming :
0 commit comments