only show token costs if usage exists

This commit is contained in:
Joshua Vial 2023-09-08 11:49:41 +12:00
parent 93ea45f588
commit 166984e94a

View file

@ -606,6 +606,8 @@ class Coder:
self.io.tool_error(show_content_err)
raise Exception("No data found in openai response!")
tokens = None
if hasattr(completion, 'usage'):
prompt_tokens = completion.usage.prompt_tokens
completion_tokens = completion.usage.completion_tokens
@ -625,6 +627,8 @@ class Coder:
show_resp = Text(show_resp or "<no response>")
self.io.console.print(show_resp)
if tokens is not None:
self.io.tool_output(tokens)
def show_send_output_stream(self, completion):