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)
| 13 | logger = logging.getLogger(__name__) |
| 14 | |
| 15 | def 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'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 | |
| 43 | def augment_system_prompt(system_prompt: str, strategies: List[Any]) -> str: |
| 44 | """ |
no outgoing calls
no test coverage detected