fix: Properly refactor mdstream from Coder into IO

This commit is contained in:
Paul Gauthier 2024-09-24 11:52:43 -07:00
parent 46ab701782
commit 117ff96c76
2 changed files with 19 additions and 13 deletions

View file

@ -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")

View file

@ -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 "<no response>")
self.console.print(show_resp)
return mdStream
def print(self, message=""):
print(message)