refactor: Simplify reasoning tag handling and remove unused function

This commit is contained in:
Paul Gauthier 2025-03-07 16:26:47 -08:00 committed by Paul Gauthier (aider)
parent 8fb235c3f5
commit de4693cdf3
2 changed files with 15 additions and 26 deletions

View file

@ -1743,11 +1743,13 @@ class Coder:
show_resp = self.render_incremental_response(True) show_resp = self.render_incremental_response(True)
if reasoning_content: if reasoning_content:
formatted_reasoning = ( formatted_reasoning = format_reasoning_content(
format_reasoning_content(reasoning_content, self.reasoning_tag_name) + "\n\n" reasoning_content, self.reasoning_tag_name
) )
show_resp = formatted_reasoning + show_resp 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()) self.io.assistant_output(show_resp, pretty=self.show_pretty())
if ( if (

View file

@ -2,12 +2,15 @@
import re import re
# Standard tag identifier from aider.dump import dump # noqa
# Standard tag identifier
REASONING_TAG = "thinking-content-" + "7bbeb8e1441453ad999a0bbba8a46d4b" REASONING_TAG = "thinking-content-" + "7bbeb8e1441453ad999a0bbba8a46d4b"
# Output formatting # Output formatting
REASONING_START = "> Thinking ..." REASONING_START = "> Thinking ..."
REASONING_END = "> ... done thinking.\n\n------" REASONING_END = "> ... done thinking.\n\n------"
def replace_reasoning_tags(text, tag_name): def replace_reasoning_tags(text, tag_name):
""" """
Replace opening and closing reasoning tags with standard formatting. 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 # Replace opening tag with proper spacing
text = re.sub(f"\\s*<{tag_name}>\\s*", f"\n{REASONING_START}\n\n", text) text = re.sub(f"\\s*<{tag_name}>\\s*", f"\n{REASONING_START}\n\n", text)
# Replace closing tag with proper spacing # Replace closing tag with proper spacing
text = re.sub(f"\\s*</{tag_name}>\\s*", f"\n\n{REASONING_END}\n\n", text) text = re.sub(f"\\s*</{tag_name}>\\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 return text
def format_reasoning_content(reasoning_content, tag_name): def format_reasoning_content(reasoning_content, tag_name):
""" """
Format reasoning content with appropriate tags. Format reasoning content with appropriate tags.
Args: Args:
reasoning_content (str): The content to format reasoning_content (str): The content to format
tag_name (str): The tag name to use tag_name (str): The tag name to use
Returns: Returns:
str: Formatted reasoning content with tags str: Formatted reasoning content with tags
""" """
if not reasoning_content: if not reasoning_content:
return "" return ""
formatted = f"<{tag_name}>\n\n{reasoning_content}\n\n</{tag_name}>"
return replace_reasoning_tags(formatted, tag_name)
def detect_reasoning_tag(text, tag_name): formatted = f"<{tag_name}>\n\n{reasoning_content}\n\n</{tag_name}>"
""" return formatted
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