wip: Added ai_output method to InputOutput class and modified append_chat_history method to handle linebreaks and trailing spaces.

This commit is contained in:
Paul Gauthier 2023-05-12 14:42:34 -07:00
parent 4a8c4af902
commit 6a94c3756a
2 changed files with 14 additions and 6 deletions

View file

@ -346,6 +346,7 @@ class Coder:
except KeyboardInterrupt: except KeyboardInterrupt:
interrupted = True interrupted = True
self.io.ai_output(self.resp)
return self.resp, interrupted return self.resp, interrupted
def show_send_output(self, completion, silent): def show_send_output(self, completion, silent):

View file

@ -135,16 +135,20 @@ class InputOutput:
prefix = "####" prefix = "####"
hist = inp.splitlines() hist = inp.splitlines()
hist = f"\n{prefix} ".join(hist) hist = f" \n{prefix} ".join(hist)
hist = f"""--- hist = f"""---
{prefix} {hist}""" {prefix} {hist}"""
self.append_chat_history(hist) self.append_chat_history(hist, True)
return inp return inp
# OUTPUT # OUTPUT
def ai_output(self, content):
hist = '\n' + content.strip() + '\n\n'
self.append_chat_history(hist, False)
def confirm_ask(self, question, default="y"): def confirm_ask(self, question, default="y"):
if self.yes: if self.yes:
res = "yes" res = "yes"
@ -152,7 +156,7 @@ class InputOutput:
res = prompt(question + " ", default=default) res = prompt(question + " ", default=default)
hist = f"*{question.strip()} {res}*" hist = f"*{question.strip()} {res}*"
self.append_chat_history(hist) self.append_chat_history(hist, True)
if not res: if not res:
return return
@ -166,7 +170,7 @@ class InputOutput:
def tool_error(self, message): def tool_error(self, message):
if message.strip(): if message.strip():
hist = f"*{message.strip()}*" hist = f"*{message.strip()}*"
self.append_chat_history(hist) self.append_chat_history(hist, True)
message = Text(message) message = Text(message)
self.console.print(message, style="red") self.console.print(message, style="red")
@ -175,13 +179,16 @@ class InputOutput:
if messages: if messages:
hist = " ".join(messages) hist = " ".join(messages)
hist = f"*{hist.strip()}*" hist = f"*{hist.strip()}*"
self.append_chat_history(hist) self.append_chat_history(hist, True)
messages = list(map(Text, messages)) messages = list(map(Text, messages))
self.console.print(*messages) self.console.print(*messages)
def append_chat_history(self, text, linebreak=True): def append_chat_history(self, text, linebreak):
if linebreak: if linebreak:
text = text.rstrip()
text = text + " \n" text = text + " \n"
if not text.endswith('\n'):
text += '\n'
with self.chat_history_file.open("a") as f: with self.chat_history_file.open("a") as f:
f.write(text) f.write(text)