MCPcopy Create free account
hub / github.com/algorithmicsuperintelligence/optillm / extract_thinking

Function extract_thinking

optillm/plugins/spl/utils.py:15–41  ·  view source on GitHub ↗

Extract thinking content from ... tags and the response after. Args: response: The model's response Returns: Tuple[str, Optional[str]]: The cleaned response and the thinking content (if any)

(response: str)

Source from the content-addressed store, hash-verified

13logger = logging.getLogger(__name__)
14
15def extract_thinking(response: str) -> Tuple[str, Optional[str]]:
16 """
17 Extract thinking content from <think>...</think> tags and the response after.
18
19 Args:
20 response: The model&#x27;s response
21
22 Returns:
23 Tuple[str, Optional[str]]: The cleaned response and the thinking content (if any)
24 """
25 thinking_content = None
26 final_response = response
27
28 # Check if there are thinking tags
29 think_pattern = r'<think>(.*?)</think>'
30 think_matches = re.findall(think_pattern, response, re.DOTALL)
31
32 if think_matches:
33 # Extract thinking content (concatenate if multiple blocks)
34 thinking_content = "\n".join(think_matches)
35
36 # Extract the response part (everything after the last </think> tag)
37 final_parts = response.split('</think>')
38 if len(final_parts) > 1:
39 final_response = final_parts[-1].strip()
40
41 return final_response, thinking_content
42
43def augment_system_prompt(system_prompt: str, strategies: List[Any]) -> str:
44 """

Callers 5

refine_strategyFunction · 0.90
classify_problemFunction · 0.90
generate_strategyFunction · 0.90
run_splFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected