Class: TokenHawk::ResponseAdapter

Inherits:
Object
  • Object
show all
Defined in:
lib/token_hawk/response_adapter.rb

Instance Method Summary collapse

Instance Method Details

#extract_input_tokens(response) ⇒ Object



9
10
11
12
# File 'lib/token_hawk/response_adapter.rb', line 9

def extract_input_tokens(response)
  return nil unless response.respond_to?(:usage) && response.usage
  response.usage.input_tokens
end

#extract_model(response) ⇒ Object



5
6
7
# File 'lib/token_hawk/response_adapter.rb', line 5

def extract_model(response)
  response.model if response.respond_to?(:model)
end

#extract_output_tokens(response) ⇒ Object



14
15
16
17
# File 'lib/token_hawk/response_adapter.rb', line 14

def extract_output_tokens(response)
  return nil unless response.respond_to?(:usage) && response.usage
  response.usage.output_tokens
end

#vendor_name(response) ⇒ Object



19
20
21
# File 'lib/token_hawk/response_adapter.rb', line 19

def vendor_name(response)
  Pricing.vendor_for_model(extract_model(response).to_s)
end