compass.services.openai.usage_from_response#

usage_from_response(current_usage, response)[source]#

OpenAI usage parser

Parameters:
  • current_usage (dict) – Dictionary containing current usage information. For OpenAI trackers, this may contain the keys "requests", "prompt_tokens", and "response_tokens" if there is already existing tracking information. Empty dictionaries are allowed, in which case the three keys above will be added to this input.

  • response (object) – OpenAI Completion object (openai.Completion). Must contain a usage attribute that contains prompt_tokens and completion_tokens counts as attributes.

Returns:

dict – Dictionary with updated usage statistics.