Class: Omakase::Trace
- Inherits:
-
Object
- Object
- Omakase::Trace
- Defined in:
- lib/omakase/trace.rb
Overview
The listener, printed for a human: Omakase.listener = Omakase::Trace.new.
A run reads top to bottom โ the call, the code the model wrote, the answer.
Colour when the stream is a terminal, plain when it is a log.
Constant Summary collapse
- COLOURS =
{generation: 36, ruby: 33, answer: 32}.freeze
- LIMIT =
800
Instance Method Summary collapse
- #call(event, agent:, **payload) ⇒ Object
-
#initialize(io: $stderr) ⇒ Trace
constructor
A new instance of Trace.
Constructor Details
#initialize(io: $stderr) ⇒ Trace
Returns a new instance of Trace.
11 12 13 14 |
# File 'lib/omakase/trace.rb', line 11 def initialize(io: $stderr) @io = io @colour = io.respond_to?(:tty?) && io.tty? end |
Instance Method Details
#call(event, agent:, **payload) ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/omakase/trace.rb', line 16 def call(event, agent:, **payload) head, body = case event when :generation then ["โ #{agent.class}##{payload[:name]}", inputs(payload[:inputs])] when :ruby then ["ยท ruby", "#{payload[:code].strip}\n#{outcome(payload[:outcome])}"] when :answer then ["โ #{agent.class}##{payload[:name]}", truncate(payload[:value].inspect)] else return # a listener that raises takes the run down with it end @io.puts(paint(event, head)) @io.puts(body.gsub(/^/, " ")) unless body.empty? end |