Merge pull request #244 from joshuavial/fix-openrouter-token-usage

only show token costs if usage exists
This commit is contained in:
paul-gauthier 2023-09-08 08:37:09 -07:00 committed by GitHub
commit 7ba70632e8
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

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):