Class: RubyCode::Views::AgentLoop::TokenSummary
- Inherits:
-
Object
- Object
- RubyCode::Views::AgentLoop::TokenSummary
- Defined in:
- lib/rubycode/views/agent_loop/token_summary.rb
Overview
Displays token usage and cost information
Class Method Summary collapse
- .build(tokens:, adapter:, model:, cumulative: nil) ⇒ Object
- .build_cached_line(tokens, pastel) ⇒ Object
- .build_cost_line(cost, pastel) ⇒ Object
- .build_cumulative_lines(cumulative, adapter, model, pastel) ⇒ Object
- .build_thinking_line(tokens, pastel) ⇒ Object
- .build_token_lines(tokens, cost, pastel) ⇒ Object
- .build_tokens_line(tokens, pastel) ⇒ Object
Class Method Details
.build(tokens:, adapter:, model:, cumulative: nil) ⇒ Object
8 9 10 11 12 13 14 15 16 |
# File 'lib/rubycode/views/agent_loop/token_summary.rb', line 8 def self.build(tokens:, adapter:, model:, cumulative: nil) pastel = Pastel.new cost = Pricing.calculate_cost(adapter: adapter, model: model, tokens: tokens) lines = build_token_lines(tokens, cost, pastel) lines.concat(build_cumulative_lines(cumulative, adapter, model, pastel)) if cumulative lines.join("\n") end |
.build_cached_line(tokens, pastel) ⇒ Object
37 38 39 |
# File 'lib/rubycode/views/agent_loop/token_summary.rb', line 37 def self.build_cached_line(tokens, pastel) " #{pastel.dim("Cached:")} #{pastel.green(tokens.cached.to_s)} tokens (cost saved)" end |
.build_cost_line(cost, pastel) ⇒ Object
41 42 43 |
# File 'lib/rubycode/views/agent_loop/token_summary.rb', line 41 def self.build_cost_line(cost, pastel) " #{pastel.dim("Cost:")} #{pastel.bold(Pricing.format_cost(cost))}" end |
.build_cumulative_lines(cumulative, adapter, model, pastel) ⇒ Object
45 46 47 48 49 50 |
# File 'lib/rubycode/views/agent_loop/token_summary.rb', line 45 def self.build_cumulative_lines(cumulative, adapter, model, pastel) total_cost = Pricing.calculate_cost(adapter: adapter, model: model, tokens: cumulative) [" #{pastel.dim("Session total:")} " \ "#{pastel.cyan(cumulative.total.to_s)} tokens / " \ "#{pastel.bold(Pricing.format_cost(total_cost))}"] end |
.build_thinking_line(tokens, pastel) ⇒ Object
33 34 35 |
# File 'lib/rubycode/views/agent_loop/token_summary.rb', line 33 def self.build_thinking_line(tokens, pastel) " #{pastel.dim("Thinking:")} #{pastel.yellow(tokens.thinking.to_s)} tokens" end |
.build_token_lines(tokens, cost, pastel) ⇒ Object
18 19 20 21 22 23 24 25 |
# File 'lib/rubycode/views/agent_loop/token_summary.rb', line 18 def self.build_token_lines(tokens, cost, pastel) lines = [""] lines << build_tokens_line(tokens, pastel) lines << build_thinking_line(tokens, pastel) if tokens.thinking&.positive? lines << build_cached_line(tokens, pastel) if tokens.cached&.positive? lines << build_cost_line(cost, pastel) lines end |
.build_tokens_line(tokens, pastel) ⇒ Object
27 28 29 30 31 |
# File 'lib/rubycode/views/agent_loop/token_summary.rb', line 27 def self.build_tokens_line(tokens, pastel) " #{pastel.dim("Tokens:")} " \ "#{pastel.cyan(tokens.input.to_s)} in / " \ "#{pastel.cyan(tokens.output.to_s)} out" end |