Class: DSPy::Teleprompt::GEPA

Inherits:
Teleprompter show all
Extended by:
T::Sig
Defined in:
lib/dspy/teleprompt/gepa.rb

Overview

GEPA: Genetic-Pareto Reflective Prompt Evolution optimizer Uses natural language reflection to evolve prompts through genetic algorithms and Pareto frontier selection for maintaining diverse high-performing candidates

Defined Under Namespace

Classes: CrossoverEngine, CrossoverType, ExecutionTrace, FitnessEvaluator, FitnessScore, GEPAConfig, GeneticEngine, InstructionProposer, MutationEngine, MutationType, ParetoSelector, ReflectionEngine, ReflectionResult, TraceCollector

Instance Attribute Summary collapse

Attributes inherited from Teleprompter

#evaluator, #metric

Instance Method Summary collapse

Methods inherited from Teleprompter

#create_evaluator, #ensure_typed_examples, #evaluate_program, #save_results, #validate_inputs

Constructor Details

#initialize(metric: nil, config: nil) ⇒ GEPA



2739
2740
2741
2742
# File 'lib/dspy/teleprompt/gepa.rb', line 2739

def initialize(metric: nil, config: nil)
  @config = config || GEPAConfig.new
  super(metric: metric, config: @config)
end

Instance Attribute Details

#configObject (readonly)

Returns the value of attribute config.



2731
2732
2733
# File 'lib/dspy/teleprompt/gepa.rb', line 2731

def config
  @config
end

Instance Method Details

#compile(program, trainset:, valset: nil) ⇒ Object



2752
2753
2754
2755
2756
2757
2758
2759
2760
2761
2762
2763
2764
2765
2766
2767
2768
2769
# File 'lib/dspy/teleprompt/gepa.rb', line 2752

def compile(program, trainset:, valset: nil)
  validate_inputs(program, trainset, valset)

  instrument_step('gepa_compile', {
    trainset_size: trainset.size,
    valset_size: valset&.size || 0,
    num_generations: @config.num_generations,
    population_size: @config.population_size
  }) do
    # Simple optimization for Phase 1.5 - basic instruction optimization
    if @config.simple_mode
      perform_simple_optimization(program, trainset, valset)
    else
      # Phase 2 - Full GEPA genetic algorithm implementation
      perform_gepa_optimization(program, trainset, valset)
    end
  end
end