Class: DSPy::Teleprompt::GEPA::ReflectionResult
- Inherits:
-
Object
- Object
- DSPy::Teleprompt::GEPA::ReflectionResult
- Extended by:
- T::Sig
- Defined in:
- lib/dspy/teleprompt/gepa.rb
Overview
Immutable reflection analysis result using Ruby’s Data class Stores the output of GEPA’s reflective analysis on execution traces
Constant Summary collapse
- ImprovementsList =
Type aliases for better type safety
T.type_alias { T::Array[String] }
- MutationsList =
T.type_alias { T::Array[Symbol] }
- MetadataHash =
T.type_alias { T::Hash[Symbol, T.untyped] }
Instance Method Summary collapse
- #actionable? ⇒ Boolean
- #analysis_duration_ms ⇒ Object
- #high_confidence? ⇒ Boolean
-
#initialize(trace_id:, diagnosis:, improvements:, confidence:, reasoning:, suggested_mutations:, metadata:) ⇒ ReflectionResult
constructor
A new instance of ReflectionResult.
- #mutation_priority ⇒ Object
- #reflection_model ⇒ Object
- #summary ⇒ Object
- #to_h ⇒ Object
- #token_usage ⇒ Object
Constructor Details
#initialize(trace_id:, diagnosis:, improvements:, confidence:, reasoning:, suggested_mutations:, metadata:) ⇒ ReflectionResult
Returns a new instance of ReflectionResult.
181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 |
# File 'lib/dspy/teleprompt/gepa.rb', line 181 def initialize(trace_id:, diagnosis:, improvements:, confidence:, reasoning:, suggested_mutations:, metadata:) # Validate confidence score if confidence < 0.0 || confidence > 1.0 raise ArgumentError, "confidence must be between 0 and 1, got #{confidence}" end # Freeze nested structures for true immutability frozen_improvements = improvements.freeze frozen_mutations = suggested_mutations.freeze = .freeze super( trace_id: trace_id, diagnosis: diagnosis, improvements: frozen_improvements, confidence: confidence, reasoning: reasoning, suggested_mutations: frozen_mutations, metadata: ) end |
Instance Method Details
#actionable? ⇒ Boolean
211 212 213 |
# File 'lib/dspy/teleprompt/gepa.rb', line 211 def actionable? improvements.any? || suggested_mutations.any? end |
#analysis_duration_ms ⇒ Object
261 262 263 |
# File 'lib/dspy/teleprompt/gepa.rb', line 261 def analysis_duration_ms [:analysis_duration_ms] || 0 end |
#high_confidence? ⇒ Boolean
205 206 207 |
# File 'lib/dspy/teleprompt/gepa.rb', line 205 def high_confidence? confidence >= 0.8 end |
#mutation_priority ⇒ Object
217 218 219 |
# File 'lib/dspy/teleprompt/gepa.rb', line 217 def mutation_priority suggested_mutations.sort end |
#reflection_model ⇒ Object
249 250 251 |
# File 'lib/dspy/teleprompt/gepa.rb', line 249 def reflection_model [:reflection_model] end |
#summary ⇒ Object
237 238 239 240 241 242 243 244 245 |
# File 'lib/dspy/teleprompt/gepa.rb', line 237 def summary confidence_pct = (confidence * 100).round mutation_list = suggested_mutations.map(&:to_s).join(', ') "#{diagnosis.split('.').first}. " \ "Confidence: #{confidence_pct}%. " \ "#{improvements.size} improvements suggested. " \ "Mutations: #{mutation_list}." end |
#to_h ⇒ Object
223 224 225 226 227 228 229 230 231 232 233 |
# File 'lib/dspy/teleprompt/gepa.rb', line 223 def to_h { trace_id: trace_id, diagnosis: diagnosis, improvements: improvements, confidence: confidence, reasoning: reasoning, suggested_mutations: suggested_mutations, metadata: } end |
#token_usage ⇒ Object
255 256 257 |
# File 'lib/dspy/teleprompt/gepa.rb', line 255 def token_usage [:token_usage] || 0 end |