Skip to content

Commit

Permalink
fix: flatten usage conditional
Browse files Browse the repository at this point in the history
  • Loading branch information
sjmonson committed Sep 24, 2024
1 parent 8385d7a commit 0035799
Showing 1 changed file with 10 additions and 11 deletions.
21 changes: 10 additions & 11 deletions plugins/openai_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -243,17 +243,16 @@ def streaming_request_http(self, query: dict, user_id: int, test_end_time: float

# Check for usage statistics
message = self._process_resp(resps[-1]['data'])
if message:
# If stream_options.include_usage == True then the final
# message contains only token stats
if not message.get("choices") and message.get('usage'):
result.output_tokens = deepget(message, "usage", "completion_tokens")
result.input_tokens = deepget(message, "usage", "prompt_tokens")
# We don't want to record this message
resps.pop()
else:
# TODO This signals that the request is faulty
logger.warn("Usage token missing")
# If stream_options.include_usage == True then the final
# message contains only token stats
if message and not message.get("choices") and message.get('usage'):
result.output_tokens = deepget(message, "usage", "completion_tokens")
result.input_tokens = deepget(message, "usage", "prompt_tokens")
# We don't want to record this message
resps.pop()
else:
# TODO This signals that the request is faulty
logger.warn("Usage token missing")

# Iterate through all responses
tokens = []
Expand Down

0 comments on commit 0035799

Please sign in to comment.