mirror of
https://github.com/Aider-AI/aider.git
synced 2025-06-01 02:05:00 +00:00
refactor: Use class attribute for reasoning tag name in replace_reasoning_tags method
This commit is contained in:
parent
634745c818
commit
b62e00b935
1 changed files with 9 additions and 8 deletions
|
@ -379,6 +379,8 @@ class Coder:
|
||||||
self.pretty = self.io.pretty
|
self.pretty = self.io.pretty
|
||||||
|
|
||||||
self.main_model = main_model
|
self.main_model = main_model
|
||||||
|
# Set the reasoning tag name based on model settings or default
|
||||||
|
self.reasoning_tag_name = self.main_model.remove_reasoning if self.main_model.remove_reasoning else REASONING_TAG
|
||||||
|
|
||||||
self.stream = stream and main_model.streaming
|
self.stream = stream and main_model.streaming
|
||||||
|
|
||||||
|
@ -1692,14 +1694,13 @@ class Coder:
|
||||||
if args:
|
if args:
|
||||||
self.io.ai_output(json.dumps(args, indent=4))
|
self.io.ai_output(json.dumps(args, indent=4))
|
||||||
|
|
||||||
def replace_reasoning_tags(self, text, tag_name):
|
def replace_reasoning_tags(self, text):
|
||||||
"""
|
"""
|
||||||
Replace opening and closing reasoning tags with standard formatting.
|
Replace opening and closing reasoning tags with standard formatting.
|
||||||
Ensures exactly one blank line before START and END markers.
|
Ensures exactly one blank line before START and END markers.
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
text (str): The text containing the tags
|
text (str): The text containing the tags
|
||||||
tag_name (str): The name of the tag to replace
|
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
str: Text with reasoning tags replaced with standard format
|
str: Text with reasoning tags replaced with standard format
|
||||||
|
@ -1717,14 +1718,14 @@ class Coder:
|
||||||
return match.group(1)
|
return match.group(1)
|
||||||
|
|
||||||
# Replace opening tag with proper spacing
|
# Replace opening tag with proper spacing
|
||||||
text = re.sub(f"\\s*<{tag_name}>\\s*", f"\n\n{REASONING_START}\n\n", text)
|
text = re.sub(f"\\s*<{self.reasoning_tag_name}>\\s*", f"\n\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*</{self.reasoning_tag_name}>\\s*", f"\n\n{REASONING_END}\n\n", text)
|
||||||
|
|
||||||
# Clean up any excessive newlines (more than 2 consecutive)
|
# Clean up any excessive newlines (more than 2 consecutive)
|
||||||
text = re.sub(r"\n{3,}", "\n\n", text)
|
text = re.sub(r"\n{3,}", "\n\n", text)
|
||||||
|
|
||||||
return text
|
return text
|
||||||
|
|
||||||
def show_send_output(self, completion):
|
def show_send_output(self, completion):
|
||||||
|
@ -1842,7 +1843,7 @@ class Coder:
|
||||||
elif text:
|
elif text:
|
||||||
# Apply reasoning tag formatting
|
# Apply reasoning tag formatting
|
||||||
if self.got_reasoning_content:
|
if self.got_reasoning_content:
|
||||||
text = self.replace_reasoning_tags(text, REASONING_TAG)
|
text = self.replace_reasoning_tags(text)
|
||||||
try:
|
try:
|
||||||
sys.stdout.write(text)
|
sys.stdout.write(text)
|
||||||
except UnicodeEncodeError:
|
except UnicodeEncodeError:
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue