Class: Smith::Workflow::UsageEntry

Inherits:
Struct
  • Object
show all
Defined in:
lib/smith/workflow/usage_entry.rb

Overview

One row per agent provider call. usage_id is a UUID generated at recording time and stable across persist/restore so hosts can use it as an idempotency anchor. rubocop:disable Style/RedundantStructKeywordInit

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(**attributes) ⇒ UsageEntry

Returns a new instance of UsageEntry.



21
22
23
24
25
26
27
# File 'lib/smith/workflow/usage_entry.rb', line 21

def initialize(**attributes)
  attributes = attributes.transform_values do |value|
    value.is_a?(String) ? value.dup.freeze : value
  end
  super(**attributes) # rubocop:disable Style/SuperArguments
  freeze
end

Instance Attribute Details

#agent_nameObject

Returns the value of attribute agent_name

Returns:

  • (Object)

    the current value of agent_name



9
10
11
# File 'lib/smith/workflow/usage_entry.rb', line 9

def agent_name
  @agent_name
end

#attempt_kindObject

Returns the value of attribute attempt_kind

Returns:

  • (Object)

    the current value of attempt_kind



9
10
11
# File 'lib/smith/workflow/usage_entry.rb', line 9

def attempt_kind
  @attempt_kind
end

#costObject

Returns the value of attribute cost

Returns:

  • (Object)

    the current value of cost



9
10
11
# File 'lib/smith/workflow/usage_entry.rb', line 9

def cost
  @cost
end

#input_tokensObject

Returns the value of attribute input_tokens

Returns:

  • (Object)

    the current value of input_tokens



9
10
11
# File 'lib/smith/workflow/usage_entry.rb', line 9

def input_tokens
  @input_tokens
end

#modelObject

Returns the value of attribute model

Returns:

  • (Object)

    the current value of model



9
10
11
# File 'lib/smith/workflow/usage_entry.rb', line 9

def model
  @model
end

#output_tokensObject

Returns the value of attribute output_tokens

Returns:

  • (Object)

    the current value of output_tokens



9
10
11
# File 'lib/smith/workflow/usage_entry.rb', line 9

def output_tokens
  @output_tokens
end

#providerObject

Returns the value of attribute provider

Returns:

  • (Object)

    the current value of provider



9
10
11
# File 'lib/smith/workflow/usage_entry.rb', line 9

def provider
  @provider
end

#recorded_atObject

Returns the value of attribute recorded_at

Returns:

  • (Object)

    the current value of recorded_at



9
10
11
# File 'lib/smith/workflow/usage_entry.rb', line 9

def recorded_at
  @recorded_at
end

#usage_idObject

Returns the value of attribute usage_id

Returns:

  • (Object)

    the current value of usage_id



9
10
11
# File 'lib/smith/workflow/usage_entry.rb', line 9

def usage_id
  @usage_id
end

Class Method Details

.from_h(hash) ⇒ Object



29
30
31
32
33
34
35
36
# File 'lib/smith/workflow/usage_entry.rb', line 29

def self.from_h(hash)
  sym = hash.transform_keys(&:to_sym)
  filtered = sym.slice(*members)
  %i[agent_name provider attempt_kind].each do |attribute|
    filtered[attribute] = filtered[attribute].to_sym if filtered[attribute].is_a?(String)
  end
  new(**filtered)
end