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.
63 64 65 66 67 68 69 70 71 72 73 74 75 76 |
# File 'lib/dspy/teleprompt/gepa.rb', line 63 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
80 81 82 |
# File 'lib/dspy/teleprompt/gepa.rb', line 80 def llm_trace? event_name.start_with?('llm.') || event_name.start_with?('lm.') end |
#model_name ⇒ Object
141 142 143 |
# File 'lib/dspy/teleprompt/gepa.rb', line 141 def model_name attributes['gen_ai.request.model'] || attributes[:model] end |
#module_trace? ⇒ Boolean
86 87 88 89 90 91 92 93 |
# File 'lib/dspy/teleprompt/gepa.rb', line 86 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
129 130 131 |
# File 'lib/dspy/teleprompt/gepa.rb', line 129 def prompt_text attributes[:prompt] || attributes['prompt'] end |
#response_text ⇒ Object
135 136 137 |
# File 'lib/dspy/teleprompt/gepa.rb', line 135 def response_text attributes[:response] || attributes['response'] end |
#signature_name ⇒ Object
147 148 149 |
# File 'lib/dspy/teleprompt/gepa.rb', line 147 def signature_name attributes['dspy.signature'] || attributes[:signature] end |
#to_h ⇒ Object
116 117 118 119 120 121 122 123 124 125 |
# File 'lib/dspy/teleprompt/gepa.rb', line 116 def to_h { trace_id: trace_id, event_name: event_name, timestamp: , span_id: span_id, attributes: attributes, metadata: } end |
#token_usage ⇒ Object
97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 |
# File 'lib/dspy/teleprompt/gepa.rb', line 97 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 |