From de4693cdf3e8c497515145b282b3e8df9141e59c Mon Sep 17 00:00:00 2001 From: Paul Gauthier Date: Fri, 7 Mar 2025 16:26:47 -0800 Subject: [PATCH] refactor: Simplify reasoning tag handling and remove unused function --- aider/coders/base_coder.py | 6 ++++-- aider/reasoning_tags.py | 35 +++++++++++------------------------ 2 files changed, 15 insertions(+), 26 deletions(-) diff --git a/aider/coders/base_coder.py b/aider/coders/base_coder.py index 51fbc6fbc..2439ec33d 100755 --- a/aider/coders/base_coder.py +++ b/aider/coders/base_coder.py @@ -1743,11 +1743,13 @@ class Coder: show_resp = self.render_incremental_response(True) if reasoning_content: - formatted_reasoning = ( - format_reasoning_content(reasoning_content, self.reasoning_tag_name) + "\n\n" + formatted_reasoning = format_reasoning_content( + reasoning_content, self.reasoning_tag_name ) show_resp = formatted_reasoning + show_resp + show_resp = replace_reasoning_tags(show_resp, self.reasoning_tag_name) + self.io.assistant_output(show_resp, pretty=self.show_pretty()) if ( diff --git a/aider/reasoning_tags.py b/aider/reasoning_tags.py index fae4914a0..d7af23e9e 100644 --- a/aider/reasoning_tags.py +++ b/aider/reasoning_tags.py @@ -2,12 +2,15 @@ import re -# Standard tag identifier +from aider.dump import dump # noqa + +# Standard tag identifier REASONING_TAG = "thinking-content-" + "7bbeb8e1441453ad999a0bbba8a46d4b" # Output formatting REASONING_START = "> Thinking ..." REASONING_END = "> ... done thinking.\n\n------" + def replace_reasoning_tags(text, tag_name): """ Replace opening and closing reasoning tags with standard formatting. @@ -25,42 +28,26 @@ def replace_reasoning_tags(text, tag_name): # Replace opening tag with proper spacing text = re.sub(f"\\s*<{tag_name}>\\s*", f"\n{REASONING_START}\n\n", text) - + # Replace closing tag with proper spacing text = re.sub(f"\\s*\\s*", f"\n\n{REASONING_END}\n\n", text) - - # Clean up any excessive newlines (more than 2 consecutive) - text = re.sub(r"\n{3,}", "\n\n", text) - + return text + def format_reasoning_content(reasoning_content, tag_name): """ Format reasoning content with appropriate tags. - + Args: reasoning_content (str): The content to format tag_name (str): The tag name to use - + Returns: str: Formatted reasoning content with tags """ if not reasoning_content: return "" - - formatted = f"<{tag_name}>\n\n{reasoning_content}\n\n" - return replace_reasoning_tags(formatted, tag_name) -def detect_reasoning_tag(text, tag_name): - """ - Detect if text contains reasoning tags. - - Args: - text (str): The text to check - tag_name (str): The tag name to look for - - Returns: - bool: True if text contains reasoning tags - """ - opening_pattern = f"<{tag_name}>" - return opening_pattern in text + formatted = f"<{tag_name}>\n\n{reasoning_content}\n\n" + return formatted