Class: DSPy::Teleprompt::GEPA::ExecutionTrace
- Inherits:
-
Object
- Object
- DSPy::Teleprompt::GEPA::ExecutionTrace
- Extended by:
- T::Sig
- Defined in:
- lib/dspy/teleprompt/gepa.rb
Overview
Immutable execution trace record using Ruby’s Data class Captures execution events for GEPA’s reflective analysis
Constant Summary collapse
- AttributesHash =
Type aliases for better type safety
T.type_alias { T::Hash[T.any(String, Symbol), T.untyped] }
- MetadataHash =
T.type_alias { T::Hash[Symbol, T.untyped] }
Instance Method Summary collapse
-
#initialize(trace_id:, event_name:, timestamp:, span_id: nil, attributes: {}, metadata: nil) ⇒ ExecutionTrace
constructor
A new instance of ExecutionTrace.
- #llm_trace? ⇒ Boolean
- #model_name ⇒ Object
- #module_trace? ⇒ Boolean
- #prompt_text ⇒ Object
- #response_text ⇒ Object
- #signature_name ⇒ Object
- #to_h ⇒ Object
- #token_usage ⇒ Object
Constructor Details
#initialize(trace_id:, event_name:, timestamp:, span_id: nil, attributes: {}, metadata: nil) ⇒ ExecutionTrace
Returns a new instance of ExecutionTrace.
62 63 64 65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/dspy/teleprompt/gepa.rb', line 62 def initialize(trace_id:, event_name:, timestamp:, span_id: nil, attributes: {}, metadata: nil) # Freeze nested structures for true immutability frozen_attributes = attributes.freeze = &.freeze super( trace_id: trace_id, event_name: event_name, timestamp: , span_id: span_id, attributes: frozen_attributes, metadata: ) end |
Instance Method Details
#llm_trace? ⇒ Boolean
79 80 81 |
# File 'lib/dspy/teleprompt/gepa.rb', line 79 def llm_trace? event_name.start_with?('llm.') || event_name.start_with?('lm.') end |
#model_name ⇒ Object
140 141 142 |
# File 'lib/dspy/teleprompt/gepa.rb', line 140 def model_name attributes['gen_ai.request.model'] || attributes[:model] end |
#module_trace? ⇒ Boolean
85 86 87 88 89 90 91 92 |
# File 'lib/dspy/teleprompt/gepa.rb', line 85 def module_trace? !llm_trace? && ( event_name.include?('chain_of_thought') || event_name.include?('react') || event_name.include?('codeact') || event_name.include?('predict') ) end |
#prompt_text ⇒ Object
128 129 130 |
# File 'lib/dspy/teleprompt/gepa.rb', line 128 def prompt_text attributes[:prompt] || attributes['prompt'] end |
#response_text ⇒ Object
134 135 136 |
# File 'lib/dspy/teleprompt/gepa.rb', line 134 def response_text attributes[:response] || attributes['response'] end |
#signature_name ⇒ Object
146 147 148 |
# File 'lib/dspy/teleprompt/gepa.rb', line 146 def signature_name attributes['dspy.signature'] || attributes[:signature] end |
#to_h ⇒ Object
115 116 117 118 119 120 121 122 123 124 |
# File 'lib/dspy/teleprompt/gepa.rb', line 115 def to_h { trace_id: trace_id, event_name: event_name, timestamp: , span_id: span_id, attributes: attributes, metadata: } end |
#token_usage ⇒ Object
96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 |
# File 'lib/dspy/teleprompt/gepa.rb', line 96 def token_usage return 0 unless llm_trace? # Try different token attribute keys [ 'gen_ai.usage.total_tokens', 'gen_ai.usage.prompt_tokens', 'tokens', :tokens ].each do |key| value = attributes[key] return value.to_i if value end 0 end |