From 117ff96c76ae3776774fe41972cd77007d02b0c7 Mon Sep 17 00:00:00 2001 From: Paul Gauthier Date: Tue, 24 Sep 2024 11:52:43 -0700 Subject: [PATCH] fix: Properly refactor mdstream from Coder into IO --- aider/coders/base_coder.py | 7 +++++-- aider/io.py | 25 ++++++++++++++----------- 2 files changed, 19 insertions(+), 13 deletions(-) diff --git a/aider/coders/base_coder.py b/aider/coders/base_coder.py index 3960515af..df09c6aa4 100755 --- a/aider/coders/base_coder.py +++ b/aider/coders/base_coder.py @@ -1102,7 +1102,10 @@ class Coder: utils.show_messages(messages, functions=self.functions) self.multi_response_content = "" - self.mdstream = self.io.assistant_output("", self.stream) + if self.show_pretty() and self.stream: + self.mdstream = self.io.get_assistant_mdstream() + else: + self.mdstream = None retry_delay = 0.125 @@ -1459,7 +1462,7 @@ class Coder: raise Exception("No data found in LLM response!") show_resp = self.render_incremental_response(True) - self.io.assistant_output(show_resp) + self.io.assistant_output(show_resp, pretty=self.show_pretty()) if ( hasattr(completion.choices[0], "finish_reason") diff --git a/aider/io.py b/aider/io.py index 37426bbf6..c12f78ecc 100644 --- a/aider/io.py +++ b/aider/io.py @@ -592,23 +592,26 @@ class InputOutput: style = RichStyle(**style) self.console.print(*messages, style=style) - def assistant_output(self, message, stream=False): - mdStream = None + def get_assistant_mdstream(self): + mdargs = dict(style=self.assistant_output_color, code_theme=self.code_theme) + mdStream = MarkdownStream(mdargs=mdargs) + return mdStream + + def assistant_output(self, message, pretty=None): show_resp = message - if self.pretty: - if stream: - mdargs = dict(style=self.assistant_output_color, code_theme=self.code_theme) - mdStream = MarkdownStream(mdargs=mdargs) - else: - show_resp = Markdown( - message, style=self.assistant_output_color, code_theme=self.code_theme - ) + # Coder will force pretty off if fence is not triple-backticks + if pretty is None: + pretty = self.pretty + + if pretty: + show_resp = Markdown( + message, style=self.assistant_output_color, code_theme=self.code_theme + ) else: show_resp = Text(message or "") self.console.print(show_resp) - return mdStream def print(self, message=""): print(message)