fixed bug in show_send_output(), more robust error handling/reporting

This commit is contained in:
Paul Gauthier 2023-06-24 07:24:04 -07:00
parent 29943b8c21
commit 7d2fc1b2d9

View file

@ -373,6 +373,7 @@ class Coder:
utils.show_messages(messages) utils.show_messages(messages)
exhausted = False exhausted = False
interrupted = False
try: try:
interrupted = self.send(messages, functions=self.functions) interrupted = self.send(messages, functions=self.functions)
except ExhaustedContextWindow: except ExhaustedContextWindow:
@ -389,7 +390,13 @@ class Coder:
self.io.tool_error(" - Use /clear to clear chat history.") self.io.tool_error(" - Use /clear to clear chat history.")
return return
content = self.partial_response_content if self.partial_response_function_call:
args = self.parse_partial_args()
content = args["explanation"]
elif self.partial_response_content:
content = self.partial_response_content
else:
content = ""
if interrupted: if interrupted:
self.io.tool_error("\n\n^C KeyboardInterrupt") self.io.tool_error("\n\n^C KeyboardInterrupt")
@ -405,6 +412,7 @@ class Coder:
if edit_error: if edit_error:
return edit_error return edit_error
# TODO: this shouldn't use content, should use self.partial_....
self.update_cur_messages(content, edited) self.update_cur_messages(content, edited)
if edited: if edited:
@ -528,14 +536,19 @@ class Coder:
def show_send_output(self, completion, silent): def show_send_output(self, completion, silent):
try: try:
self.partial_response_function_call = completion.choices[0].function_call self.partial_response_function_call = completion.choices[0].message.function_call
except AttributeError: except AttributeError as func_err:
pass show_func_err = func_err
try: try:
self.partial_response_content = completion.choices[0].message.content self.partial_response_content = completion.choices[0].message.content
except AttributeError: except AttributeError as content_err:
pass show_content_err = content_err
if not self.partial_response_function_call and not self.partial_response_content:
self.io.tool_error(show_func_err)
self.io.tool_error(show_content_err)
raise Exception("No data found in openai response!")
prompt_tokens = completion.usage.prompt_tokens prompt_tokens = completion.usage.prompt_tokens
completion_tokens = completion.usage.completion_tokens completion_tokens = completion.usage.completion_tokens