Class: RubyLLM::Contract::Pipeline::Trace
- Inherits:
-
Object
- Object
- RubyLLM::Contract::Pipeline::Trace
- Includes:
- Concerns::DeepFreeze, Concerns::TraceEquality
- Defined in:
- lib/ruby_llm/contract/pipeline/trace.rb
Constant Summary collapse
- KNOWN_KEYS =
%i[trace_id total_latency_ms total_usage step_traces total_cost].freeze
Instance Attribute Summary collapse
-
#step_traces ⇒ Object
readonly
Returns the value of attribute step_traces.
-
#total_cost ⇒ Object
readonly
Returns the value of attribute total_cost.
-
#total_latency_ms ⇒ Object
readonly
Returns the value of attribute total_latency_ms.
-
#total_usage ⇒ Object
readonly
Returns the value of attribute total_usage.
-
#trace_id ⇒ Object
readonly
Returns the value of attribute trace_id.
Instance Method Summary collapse
- #[](key) ⇒ Object
- #dig(key, *rest) ⇒ Object
-
#initialize(trace_id: nil, total_latency_ms: nil, total_usage: nil, step_traces: nil) ⇒ Trace
constructor
A new instance of Trace.
- #to_h ⇒ Object
- #to_s ⇒ Object
Methods included from Concerns::TraceEquality
Constructor Details
#initialize(trace_id: nil, total_latency_ms: nil, total_usage: nil, step_traces: nil) ⇒ Trace
Returns a new instance of Trace.
12 13 14 15 16 17 18 19 |
# File 'lib/ruby_llm/contract/pipeline/trace.rb', line 12 def initialize(trace_id: nil, total_latency_ms: nil, total_usage: nil, step_traces: nil) @trace_id = trace_id @total_latency_ms = total_latency_ms @total_usage = deep_dup_freeze(total_usage) @step_traces = step_traces&.dup&.freeze @total_cost = calculate_total_cost freeze end |
Instance Attribute Details
#step_traces ⇒ Object (readonly)
Returns the value of attribute step_traces.
10 11 12 |
# File 'lib/ruby_llm/contract/pipeline/trace.rb', line 10 def step_traces @step_traces end |
#total_cost ⇒ Object (readonly)
Returns the value of attribute total_cost.
10 11 12 |
# File 'lib/ruby_llm/contract/pipeline/trace.rb', line 10 def total_cost @total_cost end |
#total_latency_ms ⇒ Object (readonly)
Returns the value of attribute total_latency_ms.
10 11 12 |
# File 'lib/ruby_llm/contract/pipeline/trace.rb', line 10 def total_latency_ms @total_latency_ms end |
#total_usage ⇒ Object (readonly)
Returns the value of attribute total_usage.
10 11 12 |
# File 'lib/ruby_llm/contract/pipeline/trace.rb', line 10 def total_usage @total_usage end |
#trace_id ⇒ Object (readonly)
Returns the value of attribute trace_id.
10 11 12 |
# File 'lib/ruby_llm/contract/pipeline/trace.rb', line 10 def trace_id @trace_id end |
Instance Method Details
#[](key) ⇒ Object
23 24 25 26 27 |
# File 'lib/ruby_llm/contract/pipeline/trace.rb', line 23 def [](key) return nil unless KNOWN_KEYS.include?(key.to_sym) public_send(key) end |
#dig(key, *rest) ⇒ Object
29 30 31 32 33 34 |
# File 'lib/ruby_llm/contract/pipeline/trace.rb', line 29 def dig(key, *rest) value = self[key] return value if rest.empty? || value.nil? value.dig(*rest) end |
#to_h ⇒ Object
36 37 38 39 40 |
# File 'lib/ruby_llm/contract/pipeline/trace.rb', line 36 def to_h { trace_id: @trace_id, total_latency_ms: @total_latency_ms, total_usage: @total_usage, step_traces: @step_traces, total_cost: @total_cost }.compact end |
#to_s ⇒ Object
42 43 44 |
# File 'lib/ruby_llm/contract/pipeline/trace.rb', line 42 def to_s build_summary_parts.join(" ") end |