Class: LlmCostTracker::UsageCapture

Inherits:
Data
  • Object
show all
Defined in:
lib/llm_cost_tracker/usage_capture.rb,
lib/llm_cost_tracker/usage_capture.rb

Constant Summary collapse

UNKNOWN_MODEL =
"unknown"

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#modelObject (readonly)

Returns the value of attribute model

Returns:

  • (Object)

    the current value of model



8
9
10
# File 'lib/llm_cost_tracker/usage_capture.rb', line 8

def model
  @model
end

#pricing_modeObject (readonly)

Returns the value of attribute pricing_mode

Returns:

  • (Object)

    the current value of pricing_mode



8
9
10
# File 'lib/llm_cost_tracker/usage_capture.rb', line 8

def pricing_mode
  @pricing_mode
end

#providerObject (readonly)

Returns the value of attribute provider

Returns:

  • (Object)

    the current value of provider



8
9
10
# File 'lib/llm_cost_tracker/usage_capture.rb', line 8

def provider
  @provider
end

#provider_response_idObject (readonly)

Returns the value of attribute provider_response_id

Returns:

  • (Object)

    the current value of provider_response_id



8
9
10
# File 'lib/llm_cost_tracker/usage_capture.rb', line 8

def provider_response_id
  @provider_response_id
end

#streamObject (readonly)

Returns the value of attribute stream

Returns:

  • (Object)

    the current value of stream



8
9
10
# File 'lib/llm_cost_tracker/usage_capture.rb', line 8

def stream
  @stream
end

#token_usageObject (readonly)

Returns the value of attribute token_usage

Returns:

  • (Object)

    the current value of token_usage



8
9
10
# File 'lib/llm_cost_tracker/usage_capture.rb', line 8

def token_usage
  @token_usage
end

#usage_sourceObject (readonly)

Returns the value of attribute usage_source

Returns:

  • (Object)

    the current value of usage_source



8
9
10
# File 'lib/llm_cost_tracker/usage_capture.rb', line 8

def usage_source
  @usage_source
end

Class Method Details

.build(**attributes) ⇒ Object



21
22
23
24
25
26
27
28
29
30
31
# File 'lib/llm_cost_tracker/usage_capture.rb', line 21

def self.build(**attributes)
  new(
    provider: attributes.fetch(:provider).to_s,
    model: attributes.fetch(:model).to_s.strip.presence || UNKNOWN_MODEL,
    token_usage: attributes.fetch(:token_usage),
    stream: attributes[:stream] || false,
    usage_source: attributes[:usage_source],
    provider_response_id: attributes[:provider_response_id],
    pricing_mode: Pricing.normalize_mode(attributes[:pricing_mode])
  )
end

Instance Method Details

#to_hObject



33
34
35
# File 'lib/llm_cost_tracker/usage_capture.rb', line 33

def to_h
  super.compact
end