Class: Clacky::RichUI::RichContextPanel

Inherits:
Object
  • Object
show all
Includes:
Components::BaseComponent
Defined in:
lib/clacky/rich_ui/components/sidebar_panels.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Components::BaseComponent

#colored, #muted, #status_marker, #theme, #truncate

Constructor Details

#initializeRichContextPanel

Returns a new instance of RichContextPanel.



106
107
108
# File 'lib/clacky/rich_ui/components/sidebar_panels.rb', line 106

def initialize
  @token_usage = nil
end

Instance Attribute Details

#heightObject

Returns the value of attribute height.



104
105
106
# File 'lib/clacky/rich_ui/components/sidebar_panels.rb', line 104

def height
  @height
end

#widthObject

Returns the value of attribute width.



104
105
106
# File 'lib/clacky/rich_ui/components/sidebar_panels.rb', line 104

def width
  @width
end

Instance Method Details

#renderObject



114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
# File 'lib/clacky/rich_ui/components/sidebar_panels.rb', line 114

def render
  return muted("No token data") unless @token_usage

  input  = @token_usage[:prompt_tokens] || @token_usage[:input]  || 0
  output = @token_usage[:completion_tokens] || @token_usage[:output] || 0
  total  = @token_usage[:total_tokens] || @token_usage[:total] || (input + output)
  cost   = @token_usage[:cost]

  lines = []
  lines << "#{muted("prompt:")}   #{input} tok"
  lines << "#{muted("output:")}  #{output} tok"
  lines << "#{muted("total:")}   #{total} tok"
  if cost
    lines << ""
    lines << "#{muted("cost:")}    $#{cost.round(4)}"
  end
  lines.join("\n")
end

#update_tokens(data) ⇒ Object



110
111
112
# File 'lib/clacky/rich_ui/components/sidebar_panels.rb', line 110

def update_tokens(data)
  @token_usage = data
end